public async Task<ActionResult> Create(BannerPhotographEditViewModel model) { if (ModelState.IsValid) { var newName = Guid.NewGuid().ToString() + Path.GetExtension(model.Image.FileName); FileUploadHelper.SaveImage( model.Image.InputStream, 1024, 500, Path.Combine(Server.MapPath("~/Public/Banners"), newName), FitMode.Crop); model.Banner.UriPath = newName; db.Add(model.Banner); await db.SaveChangesAsync(); return RedirectToAction("Index"); } return View(model); }
public async Task<ActionResult> Edit(BannerPhotographEditViewModel model) { ModelState.Remove("Image"); if (ModelState.IsValid) { db.Update(model.Banner); db.ExcludeFromUpdate(model.Banner, b => new { b.UriPath }); if (model.Image != null) { var fileName = db.GetValueFromDb(model.Banner, b => b.UriPath); FileUploadHelper.SaveImage( model.Image.InputStream, 1024, 500, Path.Combine(Server.MapPath("~/Public/Banners"), fileName), FitMode.Crop); } foreach (var item in model.Banner.Translations) { db.UpdateTranslation(item); } await db.SaveChangesAsync(); return RedirectToAction("Index"); } return View(model); }