示例#1
0
        public CommunicationResponse AddPayment([FromBody] AddPaymentRequest paymentRequest)
        {
            var response = new CommunicationResponse();

            try
            {
                if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false)
                {
                    response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID);
                    return(response);
                }

                var payment = new Payment
                {
                    Amount   = paymentRequest.Amount,
                    DatePaid = paymentRequest.Created,
                    PersonId = paymentRequest.PersonId
                };
                PaymentValidator.CheckIfValidPayment(payment, paymentRequest.BillId);
                _billRepository.AddPayment(payment, paymentRequest.BillId);

                response.Notifications = new List <string>
                {
                    "The payment has been added"
                };
            }
            catch (ErrorCodeException exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", paymentRequest, exception.Code);
            }
            catch (Exception exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", paymentRequest);
            }

            return(response);
        }