Ejemplo n.º 1
0
        public ActionResult DeleteItem(int id)
        {
            AdminUIHelper helper = new AdminUIHelper(itemService);

            var    model      = itemService.Get(id);
            string shortPath  = model.PhotoPath;
            string serverPath = Request.MapPath(helper.GetFullserverPath(id));

            helper.DeleteImageOnServer(serverPath, shortPath);
            helper.DeleteItemFromServer(id);

            return(RedirectToAction("AdminPanel"));
        }
Ejemplo n.º 2
0
        public ActionResult Edit([Bind(Include = "Id,Name,Description,Price,PhotoPath")] ShopItemViewModel context, HttpPostedFileBase image)
        {
            AdminUIHelper helper = new AdminUIHelper(itemService);

            string modelPath = context.PhotoPath;

            if (image != null)
            {
                string serverImgPath = Path.Combine(Server.MapPath("~/Images"), helper.GetFullImageName(image));
                image.SaveAs(serverImgPath);

                string deletePath = Request.MapPath(helper.GetFullserverPath(context.Id));
                helper.DeleteImageOnServer(deletePath);

                modelPath = "~/Images/" + helper.GetFullImageName(image);
            }

            helper.EditItemOnServer(context, modelPath);

            return(RedirectToAction("AdminPanel"));
        }