private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxType.Text)) { MessageBox.Show("Заполните все поля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { TypeofnumberBindingModel model = new TypeofnumberBindingModel { Viewnumber = textBoxType.Text, }; if (Id.HasValue) { model.Id = Id; } _logicT.CreateOrUpdate(model); MessageBox.Show("Успешно", "Сохранено", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } catch (Exception ex) { MessageBox.Show(ex.InnerException?.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public void Insert(TypeofnumberBindingModel model) { using (var context = new TravelAgencyContext()) { context.Typeofnumber.Add(CreateModel(model, new Typeofnumber(), context)); context.SaveChanges(); } }
public void CreateOrUpdate(TypeofnumberBindingModel model) { if (model.Id.HasValue) { _typeofnumberStorage.Update(model); } else { _typeofnumberStorage.Insert(model); } }
public void Update(TypeofnumberBindingModel model) { using (var context = new TravelAgencyContext()) { var element = context.Typeofnumber.FirstOrDefault(rec => rec.Typeofnumberid == model.Id); if (element == null) { throw new Exception("Тип номера не найден"); } CreateModel(model, element, context); context.SaveChanges(); } }
public void Delete(TypeofnumberBindingModel model) { var element = _typeofnumberStorage.GetElement(new TypeofnumberBindingModel { Id = model.Id }); if (element == null) { throw new Exception("Элемент не найден"); } _typeofnumberStorage.Delete(model); }
public List <TypeofnumberViewModel> GetFilteredList(TypeofnumberBindingModel model) { if (model == null) { return(null); } using (var context = new TravelAgencyContext()) { return(context.Typeofnumber .Where(rec => rec.Viewnumber == model.Viewnumber) .Select(CreateModel) .ToList()); } }
public List <TypeofnumberViewModel> Read(TypeofnumberBindingModel model) { if (model == null) { return(_typeofnumberStorage.GetFullList()); } if (model.Id.HasValue) { return(new List <TypeofnumberViewModel> { _typeofnumberStorage.GetElement(model) }); } return(_typeofnumberStorage.GetFilteredList(model)); }
public TypeofnumberViewModel GetElement(TypeofnumberBindingModel model) { if (model == null) { return(null); } using (var context = new TravelAgencyContext()) { var typeofnumber = context.Typeofnumber .FirstOrDefault(rec => rec.Typeofnumberid == model.Id); return(typeofnumber != null? CreateModel(typeofnumber) : null); } }
public void Delete(TypeofnumberBindingModel model) { using (var context = new TravelAgencyContext()) { Typeofnumber element = context.Typeofnumber.FirstOrDefault(rec => rec.Typeofnumberid == model.Id); if (element != null) { context.Typeofnumber.Remove(element); context.SaveChanges(); } else { throw new Exception("Тип номера не найден"); } } }
private Typeofnumber CreateModel(TypeofnumberBindingModel model, Typeofnumber typeofnumber, TravelAgencyContext database) { typeofnumber.Viewnumber = model.Viewnumber; return(typeofnumber); }