Fix on the admin user.
This commit is contained in:
@@ -22,6 +22,23 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
_gearRepository.Add(newGear);
|
||||
}
|
||||
|
||||
public void AddRentalGear(User connectedUser)
|
||||
{
|
||||
var rentalGear = new Gear
|
||||
{
|
||||
Name = "Rental gear",
|
||||
Manufacturer = "?",
|
||||
MainCanopy = "?",
|
||||
Aad = "Cypress/Vigil",
|
||||
MaxSize = 280,
|
||||
MinSize = 190,
|
||||
ReserveCanopy = "?",
|
||||
User = connectedUser
|
||||
};
|
||||
|
||||
_gearRepository.Add(rentalGear);
|
||||
}
|
||||
|
||||
public void DeleteGearById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
@@ -82,12 +82,12 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
var adminUser = new User
|
||||
{
|
||||
Login = "administrator",
|
||||
Password = "logsadmin"
|
||||
Password = "logsadmin",
|
||||
Email = "no mail"
|
||||
};
|
||||
_userService.AddNewUser(adminUser);
|
||||
_userService.AddNewUser(adminUser, true);
|
||||
}
|
||||
|
||||
|
||||
private readonly IAircraftService _aircraftService;
|
||||
|
||||
private readonly IJumpTypeService _jumpTypeService;
|
||||
|
||||
@@ -16,5 +16,7 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
void UpdateGear(int id, Gear gear);
|
||||
|
||||
void AddNewGear(Gear gear, User connectedUser);
|
||||
|
||||
void AddRentalGear(User connectedUser);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
|
||||
|
||||
User GetById(int userId);
|
||||
|
||||
bool AddNewUser(User user);
|
||||
bool AddNewUser(User user, bool isAdmin = false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,11 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
{
|
||||
public class UserService : IUserService
|
||||
{
|
||||
public UserService(IUserRepository userRepository)
|
||||
public UserService(IUserRepository userRepository,
|
||||
IGearService gearService)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_gearService = gearService;
|
||||
}
|
||||
|
||||
public User GetById(int userId)
|
||||
@@ -27,7 +29,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
return _userRepository.GetByLogin(login, EncryptPassword(password));
|
||||
}
|
||||
|
||||
public bool AddNewUser(User newUser)
|
||||
public bool AddNewUser(User newUser, bool isAdmin = false)
|
||||
{
|
||||
newUser.Password = EncryptPassword(newUser.Password);
|
||||
var foundUser = _userRepository.GetByLogin(newUser.Login, newUser.Password);
|
||||
@@ -35,8 +37,15 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
|
||||
if (foundUser == null)
|
||||
{
|
||||
newUser.IsAdmin = false;
|
||||
result = _userRepository.Add(newUser);
|
||||
newUser.IsAdmin = isAdmin;
|
||||
var newUserId = _userRepository.Add(newUser);
|
||||
result = (newUserId > 0);
|
||||
|
||||
if (result)
|
||||
{
|
||||
newUser.Id = newUserId;
|
||||
_gearService.AddRentalGear(newUser);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -70,5 +79,7 @@ namespace skydiveLogs_api.DomainBusiness
|
||||
}
|
||||
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
private readonly IGearService _gearService;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user