public async Task<ActionResult> AddPublisher(Publisher model) { model.Id = Guid.NewGuid().ToString(); model.DateCreated = DateTime.Now; var img = WebImage.GetImageFromRequest("file"); if(img != null) { string imgPath = @"~/Content/Image/PublisherImages/" + model.Id + "_" + Path.GetFileName(img.FileName); img.Save(imgPath); model.Thumbnail = imgPath.Replace("~", ""); } else { model.Thumbnail = "/Content/Image/PublisherImages/publisher_default.png"; } if(ModelState.IsValid) { db.Publishers.Add(model); await db.SaveChangesAsync(); return RedirectToAction("ListPublishers"); } return View("Error"); }
public async Task<ActionResult> EditPublisher(Publisher model) { model.DateModified = DateTime.Now; var img = WebImage.GetImageFromRequest("file"); if(img != null) { string imgPath = @"~/Content/Image/PublisherImages/" + model.Id + "_" + Path.GetFileName(img.FileName); img.Save(imgPath); model.Thumbnail = imgPath.Replace("~", ""); } if(ModelState.IsValid) { db.Entry(model).State = EntityState.Modified; await db.SaveChangesAsync(); return RedirectToAction("ListPublishers"); } return View("Error"); }