public async Task <IActionResult> OnPostSaveCommitteeAsync([FromBody] SaveCommitteePostData data) { try { // Check for data error. if (data == null) { return(new JsonResult(new { Result = false, Message = "Något gick fel när kommittén skulle sparas" })); } // Check that the required data was sent. if (string.IsNullOrWhiteSpace(data.Name)) { return(new JsonResult(new { Result = false, Message = "Ange ett kommitténamn" })); } var committee = await _context.Committee.FindAsync(data.CommitteeId); if (committee == null) { return(new JsonResult(new { Result = false, Message = "Kommittén hittades inte i databsen. Prova att ladda om sidan." })); } // Edit the motion data. committee.CommitteeName = data.Name; committee.Description = data.Description; // Save changes and return the new name. await _context.SaveChangesAsync(); return(new JsonResult(new { Result = true })); } catch (Exception e) { return(new JsonResult(new { Result = false, Message = "Något gick fel när kommittén skulle sparas. Exception: " + e.Message })); } }
public async Task <IActionResult> OnGetAsync(int?id) { if (!id.HasValue) { return(NotFound()); } Program = await _context.Program .FirstOrDefaultAsync(p => p.ProgramNumber == id); if (Program == null) { return(NotFound()); } await _context.SiteLoad.AddAsync(new SiteLoad { TimeStamp = DateTime.Now }); await _context.SaveChangesAsync(); return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (!id.HasValue) { return(NotFound()); } Committee = await _context.Committee .FirstOrDefaultAsync(c => c.CommitteeNumber == id); if (Committee == null) { return(NotFound()); } await _context.SiteLoad.AddAsync(new SiteLoad { TimeStamp = DateTime.Now }); await _context.SaveChangesAsync(); return(Page()); }