示例#1
0
        public ActionResult Update(ParentModel pm, String ImgUrl, String Departments, String Price)
        {
            double price;

            if (!double.TryParse(Price, out price))
            {
                Price = Price.Replace('.', ',');
            }
            try
            {
                price = double.Parse(Price);
                Item item = new Item(Departments, pm.Item.ItemName)
                {
                    ImgURL = ImgUrl, ItemName = pm.Item.ItemName, Price = price, Description = pm.Item.Description, ETag = "*"
                };
                Item exists = StorageManager.GetItem(item.RowKey);
                if (exists != null)
                {
                    StorageManager.UpdateItem(item);
                }
                else
                {
                    StorageManager.DeleteItem(pm.Item);
                    StorageManager.AddItem(item);
                }
                return(RedirectToAction("Feedback", "Home", new { message = item.ItemName + " Successfully Updated", isSuccess = true, redirectControl = "Storage", redirectAction = "ListItems" }));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Feedback", "Home", new { message = "Failed to add Item. " + e.Message, isSuccess = false, redirectControl = "Storage", redirectAction = "ListItems" }));
            }
        }
示例#2
0
        public ActionResult AddItem(String Departments, String ItemName, String Description, String Price, String ImgUrl)
        {
            double price;

            if (!double.TryParse(Price, out price))
            {
                Price = Price.Replace('.', ',');
            }
            try
            {
                price = double.Parse(Price);
                Item item = new Item(Departments, ItemName)
                {
                    ItemName = ItemName, Description = Description, Price = price, ImgURL = ImgUrl
                };
                StorageManager.AddItem(item);
                return(RedirectToAction("Feedback", "Home", new { message = item.ItemName + " Successfully Added", isSuccess = true, redirectControl = "Storage", redirectAction = "AddItem" }));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Feedback", "Home", new { message = "Failed to add Item. " + e.Message, isSuccess = false, redirectControl = "Storage", redirectAction = "AddItem" }));
            }
        }