Пример #1
0
 public void Insert(MebelBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         context.Mebel.Add(CreateModel(model, new Mebel()));
         context.SaveChanges();
     }
 }
Пример #2
0
 public void Update(MebelBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         var element = context.Mebel.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Мебель не найдена");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
Пример #3
0
        public void Delete(MebelBindingModel model)

        {
            var mebel = _mebelStorage.GetElement(new MebelBindingModel
            {
                Id = model.Id
            });

            if (mebel == null)
            {
                throw new Exception("Лечение не найдено");
            }
            _mebelStorage.Delete(model);
        }
Пример #4
0
 public List <MebelViewModel> Read(MebelBindingModel model)
 {
     if (model == null)
     {
         return(_mebelStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <MebelViewModel> {
             _mebelStorage.GetElement(model)
         });
     }
     return(_mebelStorage.GetFilteredList(model));
 }
Пример #5
0
 public void Delete(MebelBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         Mebel element = context.Mebel.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Mebel.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Мебель не найдена");
         }
     }
 }
Пример #6
0
 public List <MebelViewModel> GetFilteredList(MebelBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new MebelDatabase())
     {
         return(context.Mebel
                .Where(rec => rec.Name.Contains(model.Name))
                .Select(rec => new MebelViewModel
         {
             Id = rec.Id,
             Name = rec.Name,
             Price = rec.Price
         })
                .ToList());
     }
 }
Пример #7
0
 public MebelViewModel GetElement(MebelBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new MebelDatabase())
     {
         var component = context.Mebel
                         .FirstOrDefault(rec => rec.Name == model.Name || rec.Id == model.Id);
         return(component != null ?
                new MebelViewModel
         {
             Id = component.Id,
             Name = component.Name,
             Price = component.Price
         } :
                null);
     }
 }
Пример #8
0
        public void CreateOrUpdate(MebelBindingModel model)
        {
            var mebel = _mebelStorage.GetElement(new MebelBindingModel
            {
                Name = model.Name
            });

            if (mebel != null && mebel.Id != model.Id)
            {
                throw new Exception("Уже есть такое лечение");
            }
            if (model.Id.HasValue)
            {
                _mebelStorage.Update(model);
            }
            else
            {
                _mebelStorage.Insert(model);
            }
        }
Пример #9
0
 private Mebel CreateModel(MebelBindingModel model, Mebel mebel)
 {
     mebel.Name  = model.Name;
     mebel.Price = model.Price;
     return(mebel);
 }