public async Task <IActionResult> OnPostAsync(int id) { Advert = await _context.Advert.Include(a => a.Landlord) .Include(a => a.Uploads) .FirstOrDefaultAsync(m => m.ID == id); if (!Input.Accept && string.IsNullOrEmpty(Input.Comment)) { ModelState.AddModelError("Input.Comment", "If the advert is being rejected, a comment must be provided."); return(Page()); } if (!ModelState.IsValid) { ModelState.AddModelError("", "Comments should have between 50 and 200 characters."); return(Page()); } if (Advert != null) { Advert.Accepted = Input.Accept; Advert.Submitted = Input.Accept; // if it's rejected it should become unsubmitted Advert.Comment = Input.Accept ? "" : Input.Comment; _context.Attach(Advert).State = EntityState.Modified; await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int id) { Console.WriteLine(Input.Postcode); if (!ModelState.IsValid) { return(Page()); } var advert = await _context.Advert.FindAsync(id); if (advert != null) { advert.Title = Input.Title; advert.Description = Input.Description; advert.Postcode = Input.Postcode; advert.Submitted = Input.Submitted; advert.Accepted = false; // needs to be reevaluated if things have changed advert.Comment = ""; // if we've edited it, there should be a new comment _context.Attach(advert).State = EntityState.Modified; await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }