public async Task <IActionResult> Edit([Bind(Prefix = "Item1")] EF.Page model, [Bind(Prefix = "Item2")] bool isactive, IFormFile file) { ViewData["Title"] = "Page/Edit"; try { model.ModifiedBy = User.Identity.Name; // Update Page if (!isactive) { model.DateInactive = DateTime.Now; } await new BLL.Page(unitOfWork).Edit(model); // Update Photo IFormFile uploadedImage = file; if (uploadedImage != null && uploadedImage.ContentType.ToLower().StartsWith("image/")) { var bpagephoto = new BLL.PagePhoto(unitOfWork); var pagephotos = await bpagephoto.Find(new EF.PagePhoto { PageId = model.PageId }); if (pagephotos.Count() > 0) { await new BLL.Photo(unitOfWork).Delete(pagephotos.First().PhotoId, _environment); } var pid = await new BLL.Photo(unitOfWork).Add(_environment, file); var pp = new EF.PagePhoto(); pp.PageId = model.PageId; pp.PhotoId = pid; await new BLL.PagePhoto(unitOfWork).Edit(pp); } return(Redirect("~/Admin/Page")); } catch (DbUpdateException ex) { ModelState.AddModelError(string.Empty, "Entry is causing conflict or already exist."); return(View(new Tuple <EF.Page, bool>(model, isactive))); } }
public async Task <IActionResult> Index(EF.Page args) { ViewData["Title"] = "Pages"; ViewBag.Data = await new BLL.Page(unitOfWork).Find(args); return(View()); }