Ejemplo n.º 1
0
        public EVitamins Add_Vitamins(VitaminsAddViewModel item)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                var temp = _context.eVitamins.FirstOrDefault(x => x.Name == item.Name);
                if (temp == null)
                {
                    temp.Name        = item.Name;
                    temp.Discription = item.Discription;
                    _context.eVitamins.Add(temp);
                    _context.SaveChanges();
                    scope.Complete();
                    return(temp);
                }
            }

            throw new Exception("This item alredy in base");
        }
Ejemplo n.º 2
0
 public ActionResult Create(VitaminsAddViewModel item)
 {
     if (ModelState.IsValid)
     {
         _context.Add_Vitamins(item);
         return(RedirectToAction("Index"));
     }
     else
     {
         //item.CategoryList = _context2.Get_All()
         //.Select(r => new SelectItemViewModel
         //{
         //    Id = r.Id,
         //    Name = r.Name
         //}).ToList();
         //if (item.CategoryList.Count != 0)
         //    item.CategoryId = item.CategoryList.Last().Id;
         return(View(item));
     }
 }