public async Task <IActionResult> PostNewGuest([FromBody] Guest guest) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } var existing = await _context.Guests.FindAsync(guest.GuestId); if (existing != null) { return(BadRequest(ErrorMessageContracts.IdConflict)); } try { var uniqueInviteCode = await GetUniqueInviteCode(); guest.InviteCode = uniqueInviteCode; await _context.AddAsync(guest); await _context.SaveChangesAsync(); await SetAsHeadMemberIfAvailable(guest); } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(CreatedAtAction(nameof(PostNewGuest), guest, guest.GuestId)); }
public async Task <IActionResult> PostNewRegistry([FromBody] Models.Registry registry) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } var exists = await ExistsAsync(registry.RegistryId); if (exists) { return(BadRequest(ErrorMessageContracts.IdConflict)); } try { await _context.AddAsync(registry); await _context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(CreatedAtAction(nameof(PostNewRegistry), registry.RegistryId)); }
public async Task <IActionResult> PostNewEvent([FromBody] Event @event) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } var existing = await _context.Events.FindAsync(@event.EventId); if (existing != null) { return(BadRequest(ErrorMessageContracts.IdConflict)); } try { await _context.AddAsync(@event); await _context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(CreatedAtAction("PostNewEvent", @event, @event.EventId)); }
public async Task <IActionResult> PostNewImage([FromBody] Image image) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } var existingImage = await _context.Images.FindAsync(image.ImageId); if (existingImage != null) { return(BadRequest(ErrorMessageContracts.IdConflict)); } try { await _context.AddAsync(image); await _context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(CreatedAtAction(nameof(PostNewImage), image, image.ImageId)); }
public async Task <IActionResult> PostNewFamily([FromBody] Family family) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } var existing = await _context.Families.FindAsync(family.FamilyId); if (existing != null) { return(BadRequest(ErrorMessageContracts.IdConflict)); } try { await _context.AddAsync(family); await _context.SaveChangesAsync(); if (family.HeadMemberId.HasValue) { var headMember = await _context.Guests.FindAsync(family.HeadMemberId); headMember.FamilyId = family.FamilyId; await _context.SaveChangesAsync(); } } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } return(CreatedAtAction(nameof(PostNewFamily), family, family.FamilyId)); }