public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Destination).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DestinationExists(Destination.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (Request.Form.Files.Count > 0) { Stream s = Request.Form.Files[0].OpenReadStream(); if (s.Length < 20 * 1024 * 1024) { byte[] buffer = new byte[s.Length]; s.Read(buffer, 0, (int)s.Length); s.Close(); AcquiredItem.Attachment = buffer; AcquiredItem.AttachmentFileName = Request.Form.Files[0].FileName; AcquiredItem.AttachmentContentType = Request.Form.Files[0].ContentType; } else { s.Close(); ModelState.AddModelError(string.Empty, "The attachment is too large. The maximum size is 20MB."); return(Page()); } } _context.AcquiredItem.Add(AcquiredItem); await _context.SaveChangesAsync(); return(RedirectToPage("../Assessments/Details", new { id = AcquiredItem.AssessmentID })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } AcquiredItem originalItem = await _context.AcquiredItem.FirstOrDefaultAsync(m => m.ID == AcquiredItem.ID); if (originalItem != null && Request.Form.Files.Count == 0) { AcquiredItem.Attachment = originalItem.Attachment; AcquiredItem.AttachmentFileName = originalItem.AttachmentFileName; AcquiredItem.AttachmentContentType = originalItem.AttachmentContentType; } _context.Entry(originalItem).State = EntityState.Detached; // detach from original item so you can attach to new one if (Request.Form.Files.Count > 0) { Stream s = Request.Form.Files[0].OpenReadStream(); if (s.Length < 20 * 1024 * 1024) { byte[] buffer = new byte[s.Length]; s.Read(buffer, 0, (int)s.Length); s.Close(); AcquiredItem.Attachment = buffer; AcquiredItem.AttachmentFileName = Request.Form.Files[0].FileName; AcquiredItem.AttachmentContentType = Request.Form.Files[0].ContentType; } else { s.Close(); ModelState.AddModelError(string.Empty, "The attachment is too large. The maximum size is 20MB."); return(Page()); } } _context.Attach(AcquiredItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AcquiredItemExists(AcquiredItem.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("../Assessments/Details", new { id = AcquiredItem.AssessmentID })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.AssessmentType.Add(AssessmentType); await _context.SaveChangesAsync(); return(RedirectToPage("./Details", new { id = AssessmentType.ID })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Destination.Add(Destination); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Assessment.Add(Assessment); await _context.SaveChangesAsync(); int id = Assessment.ID; // now get all the related records to the assessment type, // so that we can add the required items to the // acquired items (with the "Acquired" checkbox false, of course). Assessment = await _context.Assessment .Include(s => s.AssessmentType) .ThenInclude(s => s.RequiredItems) .Include(s => s.AcquiredItems) .AsNoTracking() .FirstOrDefaultAsync(m => m.ID == id); foreach (RequiredItem ri in Assessment.AssessmentType.RequiredItems) { AcquiredItem ai = new AcquiredItem(); ai.Description = ri.Description; ai.Attachment = ri.Attachment; ai.AttachmentFileName = ri.AttachmentFileName; ai.AttachmentContentType = ri.AttachmentContentType; ai.AssessmentID = id; ai.Acquired = false; ai.ItemName = ri.ItemName; ai.ItemType = ri.ItemType; ai.ItemTypeID = ri.ItemTypeID; _context.AcquiredItem.Add(ai); } await _context.SaveChangesAsync(); return(RedirectToPage("./Details", new { id = Assessment.ID })); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } AssessmentType = await _context.AssessmentType.FindAsync(id); if (AssessmentType != null) { _context.AssessmentType.Remove(AssessmentType); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Destination = await _context.Destination.FindAsync(id); if (Destination != null) { _context.Destination.Remove(Destination); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Customer = await _context.Customer.FindAsync(id); if (Customer != null) { _context.Customer.Remove(Customer); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } RequiredItem = await _context.RequiredItem.FindAsync(id); int parentID = RequiredItem.AssessmentTypeID; if (RequiredItem != null) { _context.RequiredItem.Remove(RequiredItem); await _context.SaveChangesAsync(); } return(RedirectToPage("../AssessmentTypes/Details", new { id = parentID })); }