Ejemplo n.º 1
0
 public List <FlowerViewModel> Read(FlowerBindingModel model)
 {
     using (var context = new FlowerShopDatabase())
     {
         return(context.Flowers
                .Where(rec => model == null || rec.Id == model.Id)
                .Select(rec => new FlowerViewModel
         {
             Id = rec.Id,
             FlowerName = rec.FlowerName,
             Count = rec.Count,
             Price = rec.Price
         })
                .ToList());
     }
 }
Ejemplo n.º 2
0
        public void Delete(FlowerBindingModel model)
        {
            using (var context = new FlowerShopDatabase())
            {
                Flower element = context.Flowers.FirstOrDefault(rec => rec.Id == model.Id);

                if (element != null)
                {
                    context.Flowers.Remove(element);
                    context.SaveChanges();
                }
                else
                {
                    CheckingElement(element);
                }
            }
        }
Ejemplo n.º 3
0
        public void CreateOrUpdate(FlowerBindingModel model)
        {
            using (var context = new FlowerShopDatabase())
            {
                Flower element = context.Flowers.FirstOrDefault(rec => rec.FlowerName == model.FlowerName && rec.Id != model.Id);
                CheckingUniqueness(element);

                if (model.Id.HasValue)
                {
                    element = context.Flowers.FirstOrDefault(rec => rec.Id == model.Id);
                    CheckingElement(element);
                }
                else
                {
                    element = new Flower();
                    context.Flowers.Add(element);
                }
                element.Count      = model.Count;
                element.FlowerName = model.FlowerName;
                element.Price      = model.Price;
                context.SaveChanges();
            }
        }