public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Maintenance = await _context.Maintenance.FindAsync(id).ConfigureAwait(false); Maintenance.LastModifiedDate = DateTime.Now; var user = _context.Owner.FirstOrDefault(x => x.User.UserID == HttpContext.Session.GetInt32("SessionUserID")); Maintenance.LastModifiedBy = user != null ? user.Initials : "SYS"; Maintenance.IsArchive = true; _context.Attach(Maintenance).State = EntityState.Modified; if (Maintenance != null) { // _context.Maintenance.Remove(Maintenance); await _context.SaveChangesAsync().ConfigureAwait(false); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var emptyMaintenance = new Model.Maintenance(); if (await TryUpdateModelAsync <Model.Maintenance>( emptyMaintenance, "maintenance", // Prefix for form value. s => s.MaintenanceID, s => s.CommonAreaAssetID, s => s.Description, s => s.Cost, s => s.DateCompleted).ConfigureAwait(false)) { emptyMaintenance.LastModifiedDate = DateTime.Now; var user = _context.Owner.FirstOrDefault(x => x.User.UserID == HttpContext.Session.GetInt32("SessionUserID")); emptyMaintenance.LastModifiedBy = user != null ? user.Initials : "SYS"; _context.Maintenance.Add(emptyMaintenance); await _context.SaveChangesAsync().ConfigureAwait(false); return(RedirectToPage("./Index")); } PopulateAssetsDropDownList(_context, emptyMaintenance.CommonAreaAssetID); return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Maintenance = await _context.Maintenance .Include(m => m.CommonAreaAsset).FirstOrDefaultAsync(m => m.MaintenanceID == id).ConfigureAwait(false); if (Maintenance == null) { return(NotFound()); } return(Page()); }