Esempio n. 1
0
        public async Task <IActionResult> CheckIn([FromBody] CheckoutDto payload, Guid id, Guid checkId)
        {
            ApiResponse <CheckoutDto> response = new ApiResponse <CheckoutDto>();

            try
            {
                if (!response.Errors.Any())
                {
                    var userFromRepo = await _userSrv.GetUser(id);

                    if (userFromRepo == null)
                    {
                        return(BadRequest(new { errorList = "Invalid User Id" }));
                    }
                    var currentUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
                    if (currentUserId != userFromRepo.Email)
                    {
                        return(BadRequest(new { errorList = "UnAuthorized" }));
                    }
                    (List <ValidationResult> Result, CheckoutDto Checkout)errorResult = await _checkoutServ.CheckInBook(payload, checkId);

                    if (errorResult.Result.Any())
                    {
                        return(BadRequest(new { errorList = $"{errorResult.Result.FirstOrDefault().ErrorMessage}" }));
                    }
                    else
                    {
                        response.Code        = ApiResponseCodes.OK;
                        response.Description = $"Checkout successful.";
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            return(Ok(response));
        }