Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ID,Name,Description,Quantity,Price,Image")] Item item)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    dao.AddItem(item);
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                ViewBag.Message = $"Something went wrong: {e.Message}";
            }

            return(View(item));
        }
        public ActionResult AddItem(Item item)
        {
            ItemDAO         it           = new ItemDAO();
            CategoryDAO     cat          = new CategoryDAO();
            List <Category> catList      = cat.GetAll();
            Category        eachCategory = new Category();
            int             count        = catList.Count();

            for (int i = 0; i < count; i++)
            {
                if (item.CategoryName == catList[i].Name)
                {
                    item.CategoryId = catList[i].Id;
                }
            }
            if (it.AddItem(item))
            {
                SetFlash(Enums.FlashMessageType.Success, "Successfully inserted!");
                return(RedirectToAction("ViewItems", "StoreClerk"));
            }

            SetFlash(Enums.FlashMessageType.Error, "Something went wrong!");
            return(RedirectToAction("ViewItems", "StoreClerk"));
        }