예제 #1
0
        public async Task <IActionResult> UpdateGuestStay([FromBody] GuestStayForEditDto guestStayDto)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            //TODO add account type verification for tasks
            if (currentUserId == 0)
            {
                return(Unauthorized());
            }

            var gueststay = await _guestStayRepo.GetFirstOrDefault(s => s.Id == guestStayDto.Id);

            if (gueststay == null)
            {
                ModelState.AddModelError("error", "Unable to update guest");
                return(BadRequest(ModelState));
            }

            //EF errors if values are not null for update
            guestStayDto.Guest    = null;
            guestStayDto.Building = null;
            guestStayDto.Room     = null;

            _mapper.Map(guestStayDto, gueststay);
            await _guestRepo.SaveAsync();

            return(Ok());
        }
예제 #2
0
        public async Task <Stay> UpdateGuestStay(GuestStayForEditDto guestStayDto)
        {
            var gueststay = await _guestStayRepo.GetFirstOrDefault(s => s.Id == guestStayDto.Id);

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

            //EF errors if values are not null for update
            guestStayDto.Guest    = null;
            guestStayDto.Building = null;
            guestStayDto.Room     = null;

            _mapper.Map(guestStayDto, gueststay);
            await _guestRepo.SaveAsync();

            return(gueststay);
        }