예제 #1
0
 private CustomerBase CreateModel(CustomerBaseBindingModel model, CustomerBase custBase)
 {
     custBase.Surname        = model.Surname;
     custBase.Name           = model.Name;
     custBase.Lastname       = model.Lastname;
     custBase.DateOfBirthday = model.DateOfBirthday;
     return(custBase);
 }
예제 #2
0
 public void Insert(CustomerBaseBindingModel model)
 {
     using (var context = new ComputerRepairDatabase())
     {
         context.CustomerBase.Add(CreateModel(model, new CustomerBase()));
         context.SaveChanges();
     }
 }
예제 #3
0
 public List <CustomerBaseViewModel> Read(CustomerBaseBindingModel model)
 {
     if (model.Id.HasValue)
     {
         return(new List <CustomerBaseViewModel> {
             _customerBaseStorage.GetElement(model)
         });
     }
     return(_customerBaseStorage.GetFullList());
 }
예제 #4
0
 public void CreateOrUpdate(CustomerBaseBindingModel model)
 {
     if (model.Id.HasValue)
     {
         _customerBaseStorage.Update(model);
     }
     else
     {
         _customerBaseStorage.Insert(model);
     }
 }
예제 #5
0
        public void Delete(CustomerBaseBindingModel model)
        {
            var element = _customerBaseStorage.GetElement(new CustomerBaseBindingModel
            {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Элемент не найден");
            }
            _customerBaseStorage.Delete(model);
        }
예제 #6
0
 public void Update(CustomerBaseBindingModel model)
 {
     using (var context = new ComputerRepairDatabase())
     {
         var element = context.CustomerBase.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Элемент не найден");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
예제 #7
0
 public CustomerBaseViewModel GetElement(CustomerBaseBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new ComputerRepairDatabase())
     {
         var custBase = context.CustomerBase.FirstOrDefault(rec => rec.Id == model.Id);
         return(custBase != null ? new CustomerBaseViewModel
         {
             Id = custBase.Id,
             Surname = custBase.Surname,
             Name = custBase.Name,
             Lastname = custBase.Lastname,
             DateOfBirthday = custBase.DateOfBirthday
         } : null);
     }
 }