public ActionResult Create(Sale model) { try { model.Id = 0; var article = new Sale { //Name = string.IsNullOrEmpty(model.Name) // ? SiteHelper.UpdatePageWebName(model.Name, model.Title) // : SiteHelper.UpdatePageWebName(model.Name), StartDate = model.StartDate, EndDate = model.EndDate, Title = model.Title, TitleEng = model.TitleEng, Description = model.Description, DescriptionEng = model.DescriptionEng, }; 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); article.ImageSource = fileName; } else { article.ImageSource = article.ImageSource ?? ""; } _repository.AddSale(article); } catch (Exception ex) { TempData["errorMessage"] = ex.Message + (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message) ? ex.InnerException.Message : ""); return View(model); } return RedirectToAction("Index"); }
public ActionResult Edit(Sale model) { try { var article = _repository.GetSale(model.Id); //article.Name = SiteHelper.UpdatePageWebName(model.Name); TryUpdateModel(article, new[] { "Title", "TitleEng", "StartDate", "EndDate", "Description", "DescriptionEng" }); var file = Request.Files[0]; if (file != null && !string.IsNullOrEmpty(file.FileName)) { if (!string.IsNullOrEmpty(article.ImageSource)) { ImageHelper.DeleteImage(article.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); article.ImageSource = fileName; } else { article.ImageSource = article.ImageSource ?? ""; } _repository.SaveSale(article); } catch (Exception ex) { TempData["errorMessage"] = ex.Message; return View(model); } return RedirectToAction("Index"); }
public void SaveSale(Sale sale) { _store.SaveChanges(); }
public int AddSale(Sale sale) { _store.Sales.Add(sale); _store.SaveChanges(); return sale.Id; }