public async Task <IActionResult> UpdateReview([FromServices] ApplicationContext db, Review review, IFormFile PhotoFolder, IFormFile ReviewFolder) { var reviewdb = await db.Reviews.FirstOrDefaultAsync(_ => _.ID == review.ID); if (PhotoFolder == null) { review.PhotoFolder = reviewdb.PhotoFolder; } else { var folder = await Img.AddFile(PhotoFolder, _appEnvironment.WebRootPath, "img/Review"); review.PhotoFolder = folder; } if (ReviewFolder == null) { review.ReviewFolder = reviewdb.ReviewFolder; } else { var folder = await Img.AddFile(ReviewFolder, _appEnvironment.WebRootPath, "img/Review"); review.ReviewFolder = folder; } db.Entry(reviewdb).State = EntityState.Detached; db.Reviews.Update(review); await db.SaveChangesAsync(); return(RedirectToAction("Reviews", "Administration")); }
public async Task <IActionResult> AddReview([FromServices] ApplicationContext db, Review review, IFormFile PhotoFolder, IFormFile ReviewFolder) { if (PhotoFolder != null && ReviewFolder != null) { var folderP = await Img.AddFile(PhotoFolder, _appEnvironment.WebRootPath, "img/Review"); var folderR = await Img.AddFile(ReviewFolder, _appEnvironment.WebRootPath, "img/Review"); if (folderP != null && folderR != null) { review.PhotoFolder = folderP; review.ReviewFolder = folderR; db.Add(review); await db.SaveChangesAsync(); return(RedirectToAction("Reviews", "Administration")); } } return(View(review)); }