// 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(CustomMapping).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomMappingExists(CustomMapping.Id)) { return(NotFound()); } else { 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()); } var user = await _userManager.GetUserAsync(HttpContext.User); CustomMapping.Owner = user; _context.CustomMapping.Add(CustomMapping); await _context.Database.OpenConnectionAsync(); try { await _context.Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT dbo.CustomMapping ON"); await _context.SaveChangesAsync(); await _context.Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT dbo.CustomMapping OFF"); } finally { await _context.Database.CloseConnectionAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(long?id) { if (id == null) { return(NotFound()); } CustomMapping = await _context.CustomMapping.FindAsync(id); if (CustomMapping != null) { _context.CustomMapping.Remove(CustomMapping); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(long?id) { if (id == null) { return(NotFound()); } var user = await _userManager.GetUserAsync(HttpContext.User); var target = _context.CustomMapping.Find(CustomMapping.Id); if (user != target.Owner) { return(Unauthorized()); } CustomMapping = await _context.CustomMapping.FindAsync(id); if (CustomMapping != null) { _context.CustomMapping.Remove(CustomMapping); await _context.SaveChangesAsync(); } 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() { var user = await _userManager.GetUserAsync(HttpContext.User); var target = _context.Mapping.Find(Mapping.Id); _context.Entry(target).State = EntityState.Detached; if (user != target.Owner) { return(Unauthorized()); } if (!ModelState.IsValid) { return(Page()); } Mapping.OwnerId = target.OwnerId; _context.Attach(Mapping).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MappingExists(Mapping.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }