public ActionResult Edit(MainPageBanner model) { _repository.LangId = CurrentLangId; var banner = _repository.GetMainPageBanner(model.Id); var file = Request.Files[0]; if (file != null && !string.IsNullOrEmpty(file.FileName)) { if (!string.IsNullOrEmpty(banner.ImageSource)) { ImageHelper.DeleteImage(banner.ImageSource); } string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500); file.SaveAs(filePath); banner.ImageSource = fileName; } banner.Url = model.Url; _repository.SaveMainPageBanner(banner); return RedirectToAction("Index"); }
public ActionResult Create(MainPageBanner model) { _repository.LangId = CurrentLangId; try { var file = Request.Files[0]; if (file != null && !string.IsNullOrEmpty(file.FileName)) { string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500); file.SaveAs(filePath); var mainPageBanner = new MainPageBanner {IsSiteBanner = true, ImageSource = fileName, Url = model.Url}; _repository.AddMainPageBanner(mainPageBanner); } } catch (Exception ex) { TempData["errorMessage"] = ex.Message; return View(); } return RedirectToAction("Index"); }
public void SaveMainPageBanner(MainPageBanner mainPageBanner) { _store.SaveChanges(); }
public int AddMainPageBanner(MainPageBanner mainPageBanner) { _store.MainPageBanners.Add(mainPageBanner); _store.SaveChanges(); return mainPageBanner.Id; }