Fix on the admin user.

This commit is contained in:
Sébastien André
2021-03-18 15:50:41 +01:00
parent b192bb7192
commit 7caf1d7df2
16 changed files with 80 additions and 37 deletions

View File

@@ -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;
}
}