public void CreateOrUpdate(OperatorBindingModel model) { var elementByLogin = _operatorStorage.GetElement(new OperatorBindingModel { Login = model.Login }); if (elementByLogin != null && elementByLogin.ID != model.ID) { throw new Exception("Данный логин уже занят"); } var elementByMail = _operatorStorage.GetElement(new OperatorBindingModel { Mail = model.Mail }); if (elementByMail != null && elementByMail.ID != model.ID) { throw new Exception("Данный электронная почта уже занята"); } if (model.ID.HasValue) { _operatorStorage.Update(model); } else { _operatorStorage.Insert(model); } }
public void Insert(OperatorBindingModel model) { using (var context = new TourFirmDatabase()) { context.Operators.Add(CreateModel(model, new Operator())); context.SaveChanges(); } }
private Operator CreateModel(OperatorBindingModel model, Operator _operator) { _operator.Name = model.Name; _operator.Surname = model.Surname; _operator.PhoneNumber = model.PhoneNumber; _operator.Mail = model.Mail; _operator.Login = model.Login; _operator.Password = model.Password; return(_operator); }
public void Delete(OperatorBindingModel model) { var element = _operatorStorage.GetElement(new OperatorBindingModel { ID = model.ID }); if (element == null) { throw new Exception("Элемент не найден"); } _operatorStorage.Delete(model); }
public void Update(OperatorBindingModel model) { using (var context = new TourFirmDatabase()) { var element = context.Operators.FirstOrDefault(rec => rec.ID == model.ID); if (element == null) { throw new Exception("Элемент не найден"); } CreateModel(model, element); context.SaveChanges(); } }
public List <OperatorViewModel> Read(OperatorBindingModel model) { if (model == null) { return(_operatorStorage.GetFullList()); } if (model.ID.HasValue) { return(new List <OperatorViewModel> { _operatorStorage.GetElement(model) }); } return(null); }
public void Delete(OperatorBindingModel model) { using (var context = new TourFirmDatabase()) { var element = context.Operators.FirstOrDefault(rec => rec.ID == model.ID); if (element != null) { context.Operators.Remove(element); context.SaveChanges(); } else { throw new Exception("Элемент не найден"); } } }
public OperatorViewModel GetElement(OperatorBindingModel model) { if (model == null) { return(null); } using (var context = new TourFirmDatabase()) { var _operator = context.Operators.FirstOrDefault(rec => rec.ID == model.ID || rec.Login == model.Login || rec.Mail == model.Mail); return(_operator != null ? new OperatorViewModel { ID = _operator.ID, Name = _operator.Name, Surname = _operator.Surname, PhoneNumber = _operator.PhoneNumber, Login = _operator.Login, Mail = _operator.Mail, Password = _operator.Password } : null); } }