示例#1
0
        public async Task <IActionResult> SolveRefund(Guid refundRequestId, [FromBody] RefundSolutionDto solution)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var request = _usersRepository.GetRefundRequest(refundRequestId);

            if (request == null)
            {
                return(NotFound());
            }

            var history = await _tripsRepository.GetTripHistory(request.TripHistoryId);

            if (history == null)
            {
                return(NotFound());
            }
            var user = _usersRepository.GetCustomerById(history.CustomerId);
            var root = (await _usersRepository.GetUsers(new UserResourceParameters()
            {
                Rol = Helpers.Constants.Strings.JwtClaims.RootUserAccess
            })).FirstOrDefault();

            if (solution.ToRefund == true)
            {
                var res = Refund.Approve((ulong)history.ContractId, new DefaultControllerPattern(),
                                         new User()
                {
                    PrivateKey = root.PrivateKey
                }, ModelState);
            }
            else
            {
                var res = Refund.DisApprove((ulong)history.ContractId, new DefaultControllerPattern(),
                                            new User()
                {
                    PrivateKey = root.PrivateKey
                }, ModelState);
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var adminid = User.Claims.FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.AdminId)?.Value;

            request.Solved = true;

            request.Message += ("\n " + solution.Message);

            _usersRepository.UpdateRefund(request);

            var responce = new AdminResponse()
            {
                AdminId      = Guid.Parse(adminid),
                CreationTime = DateTime.UtcNow,
                IdentityId   = user.Identity.Id,
                Message      = solution.Message
            };

            await _usersRepository.AddAdminResponse(responce);

            return(NoContent());
        }