Esempio n. 1
0
 private Cosmetic CreateModel(CosmeticBindingModel model, Cosmetic cosmetic)
 {
     cosmetic.CosmeticName = model.CosmeticName;
     cosmetic.Price        = model.Price;
     cosmetic.EmployeeId   = (int)model.EmployeeId;
     return(cosmetic);
 }
Esempio n. 2
0
 public void Insert(CosmeticBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         context.Cosmetics.Add(CreateModel(model, new Cosmetic()));
         context.SaveChanges();
     }
 }
        public void Delete(CosmeticBindingModel model)
        {
            var element = _cosmeticStorage.GetElement(new CosmeticBindingModel {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Косметика не найдена");
            }
            _cosmeticStorage.Delete(model);
        }
Esempio n. 4
0
 public void Update(CosmeticBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         var element = context.Cosmetics.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Элемент не найден");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
 public List <CosmeticViewModel> Read(CosmeticBindingModel model)
 {
     if (model == null)
     {
         return(_cosmeticStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <CosmeticViewModel> {
             _cosmeticStorage.GetElement(model)
         });
     }
     return(_cosmeticStorage.GetFilteredList(model));
 }
Esempio n. 6
0
 public void Delete(CosmeticBindingModel model)
 {
     using (var context = new BeautySaloonDatabase())
     {
         Cosmetic element = context.Cosmetics.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Cosmetics.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Элемент не найден");
         }
     }
 }
        public void CreateOrUpdate(CosmeticBindingModel model)
        {
            var element = _cosmeticStorage.GetElement(new CosmeticBindingModel {
                CosmeticName = model.CosmeticName
            });

            if (element != null && element.Id != model.Id)
            {
                throw new Exception("Уже есть косметика с таким названием");
            }
            if (model.Id.HasValue)
            {
                _cosmeticStorage.Update(model);
            }
            else
            {
                _cosmeticStorage.Insert(model);
            }
        }
Esempio n. 8
0
 public List <CosmeticViewModel> GetFilteredList(CosmeticBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         return(context.Cosmetics
                .Include(rec => rec.Employee)
                .Where(rec => rec.EmployeeId == model.EmployeeId || rec.CosmeticName.Contains(model.CosmeticName))
                .Select(rec => new CosmeticViewModel
         {
             Id = rec.Id,
             CosmeticName = rec.CosmeticName,
             Price = rec.Price,
             EmployeeId = rec.EmployeeId
         })
                .ToList());
     }
 }
Esempio n. 9
0
 public CosmeticViewModel GetElement(CosmeticBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new BeautySaloonDatabase())
     {
         var tmp      = model.EmployeeId;
         var cosmetic = context.Cosmetics
                        .Include(rec => rec.Employee)
                        .FirstOrDefault(rec => rec.CosmeticName == model.CosmeticName || rec.Id == model.Id);
         return(cosmetic != null ?
                new CosmeticViewModel
         {
             Id = cosmetic.Id,
             CosmeticName = cosmetic.CosmeticName,
             Price = cosmetic.Price,
             EmployeeId = cosmetic.EmployeeId
         } :
                null);
     }
 }