fix
This commit is contained in:
parent
1c94f49c82
commit
5fcd7a7018
@ -13,6 +13,85 @@ namespace UniversityBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
public class UserLogic : IUserLogic
|
public class UserLogic : IUserLogic
|
||||||
{
|
{
|
||||||
|
private readonly IUserStorage _userStorage;
|
||||||
|
|
||||||
|
public UserLogic(IUserStorage userStorage)
|
||||||
|
{
|
||||||
|
_userStorage = userStorage;
|
||||||
|
}
|
||||||
|
public bool Create(UserBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_userStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(UserBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
if (_userStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserViewModel? ReadElement(UserSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
var user = _userStorage.GetElement(model);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
||||||
|
{
|
||||||
|
var list = model == null ? _userStorage.GetFullList() : _userStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(UserBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
if (_userStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(UserBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Login))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет логина", nameof(model.Login));
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = _userStorage.GetElement(new UserSearchModel{Login = model.Login});
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Пользователь с таким логином уже есть");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user