Exemplo n.º 1
0
        public async Task <Guest> UpdateGuest(GuestForEditDto updatedGuestDto)
        {
            var guest = await _guestRepo.GetFirstOrDefault(g => g.Id == updatedGuestDto.Id);

            if (guest == null)
            {
                throw new System.ArgumentException("Unable to update guest", string.Empty);
            }

            _mapper.Map(updatedGuestDto, guest);
            await _guestRepo.SaveAsync();

            return(guest);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateGuest([FromBody] GuestForEditDto updatedGuestDto)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (currentUserId == 0)
            {
                return(Unauthorized());
            }

            try {
                await _guestStayService.UpdateGuest(updatedGuestDto);
            } catch (ArgumentException e) {
                ModelState.AddModelError("Exception", e.Message);
                return(BadRequest(ModelState));
            }

            return(Ok());
        }