Exemplo n.º 1
0
 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;
     }
 }
Exemplo n.º 2
0
 public void Insert(TypeofnumberBindingModel model)
 {
     using (var context = new TravelAgencyContext())
     {
         context.Typeofnumber.Add(CreateModel(model, new Typeofnumber(), context));
         context.SaveChanges();
     }
 }
Exemplo n.º 3
0
 public void CreateOrUpdate(TypeofnumberBindingModel model)
 {
     if (model.Id.HasValue)
     {
         _typeofnumberStorage.Update(model);
     }
     else
     {
         _typeofnumberStorage.Insert(model);
     }
 }
Exemplo n.º 4
0
 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();
     }
 }
Exemplo n.º 5
0
        public void Delete(TypeofnumberBindingModel model)
        {
            var element = _typeofnumberStorage.GetElement(new TypeofnumberBindingModel
            {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Элемент не найден");
            }
            _typeofnumberStorage.Delete(model);
        }
Exemplo n.º 6
0
 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());
     }
 }
Exemplo n.º 7
0
 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));
 }
Exemplo n.º 8
0
 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);
     }
 }
Exemplo n.º 9
0
 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("Тип номера не найден");
         }
     }
 }
Exemplo n.º 10
0
 private Typeofnumber CreateModel(TypeofnumberBindingModel model, Typeofnumber typeofnumber, TravelAgencyContext database)
 {
     typeofnumber.Viewnumber = model.Viewnumber;
     return(typeofnumber);
 }