public async Task <ActionResult <Guest> > Create([FromBody] Guest guest) { try { if (guest == null || string.IsNullOrWhiteSpace(guest.name)) { return(BadRequest("Cannot be empty or white space.")); } // avoiding duplicates var checkGuestIfExist = await _guestService.GetByName(guest.name); if (checkGuestIfExist != null) { return(BadRequest("Guest already exist.")); } guest.name = guest.name.Trim(); // Empty strings come as null guest.participate = ""; guest.plusOneName = ""; guest.created = DateTime.Now; await _guestService.Create(guest); return(Ok(guest)); } catch (System.Exception) { return(StatusCode(500)); } }
public async Task <ActionResult <Guest> > CheckGuest([FromBody] Guest guestIn) { try { var guest = await _guestService.GetByName(guestIn.name); if (guest == null) { return(NotFound("Not found")); } return(Ok(guest)); } catch (System.Exception) { return(StatusCode(500)); } }