// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { //if (!ModelState.IsValid) //{ // return Page(); //} using (var transaction = _context.Database.BeginTransaction()) { try { _context.Persons.Add(Person); await _context.SaveChangesAsync(); if (Father.RelatedPersonId > 0) { Father.Relation = Relation.ParentY; Father.PersonId = Person.PersonId; _context.PersonRelations.Add(Father); } if (Mother.RelatedPersonId > 0) { Mother.Relation = Relation.ParentX; Mother.PersonId = Person.PersonId; _context.PersonRelations.Add(Mother); } if (Spouse.RelatedPersonId > 0) { Spouse.Relation = Relation.Spouse; Spouse.PersonId = Person.PersonId; _context.PersonRelations.Add(Spouse); } await _context.SaveChangesAsync(); transaction.Commit(); } catch { transaction.Rollback(); throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(PersonImage).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonImageExists(PersonImage.PersonImageId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.PersonImages.Add(PersonImage); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } PersonRelation = await _context.PersonRelations.FindAsync(id); if (PersonRelation != null) { _context.PersonRelations.Remove(PersonRelation); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }