public async Task <IActionResult> UpdateRegistry(int id, [FromBody] Models.Registry registry) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } var exists = await ExistsAsync(registry.RegistryId); if (!exists) { return(NotFound()); } if (id != registry.RegistryId) { return(BadRequest(ErrorMessageContracts.MismatchedId)); } try { _context.Entry(registry).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(NoContent()); }
public async Task <IActionResult> UpdateAddress(int id, [FromBody] Address address) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } if (id != address.AddressId) { return(BadRequest(ErrorMessageContracts.MismatchedId)); } var existing = await _context.Addresses.FindAsync(id); if (existing == null) { return(NotFound()); } try { AddressHelper.UpdateAddress(existing, address); _context.Entry(existing).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(NoContent()); }
private async Task <bool> UpdateGuest(Guest guest) { try { var original = await _context.Guests.FindAsync(guest.GuestId); _context.Entry(original).State = EntityState.Detached; _context.Entry(guest).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception) { return(false); } return(true); }
public async Task <ActionResult> Edit([Bind(Include = "ID,ShortName,FullName")] Person person) { if (ModelState.IsValid) { db.Entry(person).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(person)); }
public async Task <IActionResult> UpdateEvent(int id, [FromBody] Event @event) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } if (id != @event.EventId) { return(BadRequest(ErrorMessageContracts.MismatchedId)); } var existing = await _context.Events.FindAsync(id); if (existing == null) { return(NotFound()); } try { existing.AddressId = @event.AddressId; existing.Description = @event.Description; existing.EndTime = @event.EndTime; existing.Name = @event.Name; existing.StartTime = @event.StartTime; _context.Entry(existing).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(NoContent()); }