Пример #1
0
        public ActionResult Create(ShopItemViewModel context, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                AdminUIHelper helper = new AdminUIHelper(itemService);

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

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

                helper.CreateItemOnServer(context, modelPath);

                return(RedirectToAction("AdminPanel"));
            }

            return(View());
        }
Пример #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"));
        }