public async Task <IActionResult> OnPostAsync(int?id) { var appUser = await AppUsers.Get(User); if (id is not null) { Link = await DataContext.HomeReviewLinks .Include(r => r.Home) .FirstOrDefaultAsync(r => r.Id == id); } if (Link is null) { return(NotFound()); } Link.Home.ModifiedById = appUser.Id; Link.Home.Modified = DateTime.Now; DataContext.Entry(Link.Home).State = EntityState.Modified; DataContext.HomeReviewLinks.Remove(Link); await DataContext.SaveChangesAsync(); return(RedirectToPage("./HomeDetails", new { Id = Link.HomeId })); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id is not null) { Link = await DataContext.HomeReviewLinks .Include(r => r.CreatedBy) .Include(r => r.ModifiedBy) .FirstOrDefaultAsync(m => m.Id == id); } if (Link is null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var appUser = await AppUsers.Get(User); var homeRecord = await DataContext.HomeReviewHomes.FindAsync(Home.Id); if (homeRecord is null) { return(NotFound()); } var linkRecord = await DataContext.HomeReviewLinks.FirstOrDefaultAsync(r => r.Link == Address); if (linkRecord is null) { linkRecord = new Data.Models.HomeReviewLink { Link = Address, HomeId = homeRecord.Id, CreatedById = appUser.Id, Created = DateTime.Now, ModifiedById = appUser.Id, Modified = DateTime.Now }; DataContext.HomeReviewLinks.Add(linkRecord); homeRecord.ModifiedById = appUser.Id; homeRecord.Modified = DateTime.Now; DataContext.Entry(homeRecord).State = EntityState.Modified; await DataContext.SaveChangesAsync(); } return(RedirectToPage("./HomeDetails", new { Home.Id })); }