public ActionResult Edit(ShopCreateVM shop) { try { if (ModelState.IsValid) { shop.Rating = _ratingLogic.GetRatingShopById(shop.IDShop); _shopLogic.Update(Mapper.Map <ShopCreateVM, Shop>(shop)); return(RedirectToAction("IndexForModerator")); } } catch (Exception ex) { ModelState.AddModelError(String.Empty, ex); } return(View(shop)); }
public ActionResult Create(ShopCreateVM shop, HttpPostedFileBase uploadFile) { try { if (uploadFile != null) { if (uploadFile.ContentLength > 0) { if (Path.GetExtension(uploadFile.FileName).ToLower() == ".jpg" || Path.GetExtension(uploadFile.FileName).ToLower() == ".png" || Path.GetExtension(uploadFile.FileName).ToLower() == ".gif" || Path.GetExtension(uploadFile.FileName).ToLower() == ".jpeg") { HttpPostedFileBase uploadFileCopy = uploadFile; string ImageName = System.IO.Path.GetFileName(uploadFileCopy.FileName); //file2 to store path and url string physicalPath = Server.MapPath("~/img/" + ImageName); // save image in folder uploadFileCopy.SaveAs(physicalPath); byte[] mas = new byte[uploadFile.ContentLength]; uploadFile.InputStream.Read(mas, 0, uploadFile.ContentLength); shop.Image = mas; } } } if (ModelState.IsValid) { shop.Moderator = (_userLogic.GetUserByEMail(System.Web.HttpContext.Current.User.Identity.Name.ToString()) ?? new Common.User()).IDUser; _shopLogic.AddShop(Mapper.Map <ShopCreateVM, Shop>(shop)); return(RedirectToAction("IndexForModerator")); } } catch (Exception ex) { ModelState.AddModelError(String.Empty, ex); } return(View(shop)); }