コード例 #1
0
        public void ValidatePagoInput_Ok()
        {
            PagoInputDataContract pago_input = new PagoInputDataContract()
            {
                Amount   = Math.Round(105.60m, 2),
                Currency = "ARS",
                User_id  = 2,
            };

            Assert.AreEqual(this.PagoInputDataContractValidator.Validate(pago_input).IsValid, true);
        }
コード例 #2
0
        public void ValidatePagoInput_User_Error()
        {
            PagoInputDataContract pago_input = new PagoInputDataContract()
            {
                Amount   = Convert.ToDecimal(100),
                Currency = "AS",
                User_id  = 0,
            };

            Assert.AreEqual(this.PagoInputDataContractValidator.Validate(pago_input).IsValid, false);
        }
コード例 #3
0
        public IList <string> GetErrorsCheckPago(PagoInputDataContract pago)
        {
            IList <string> errors = new List <string>();

            var validationResult = this.PagoInputDataContractValidator.Validate(pago);

            foreach (var error in validationResult.Errors)
            {
                errors.Add(error.ToString());
            }

            return(errors);
        }
コード例 #4
0
        public async Task <PagoOutputDataContract> CreatePago(PagoInputDataContract input, DebtInputDataContract debt)
        {
            decimal payment_Amount = GetLegalAmount(input.Currency, input.Amount);

            Pago pago = new Pago()
            {
                User_Id         = input.User_id,
                Currency        = (Currency)Enum.Parse(typeof(Currency), input.Currency),
                Amount_Currency = input.Amount,
                Amount_Legal    = payment_Amount,
                Date            = DateTime.Now,
            };

            await AddCargo(debt, payment_Amount, pago);

            PagoRepository.Save(pago);

            return(this.GetPagoById(pago.Id));
        }
コード例 #5
0
        public async Task <IActionResult> Post(PagoInputDataContract input)
        {
            if (!this.PagoService.CheckInput(input))
            {
                var errors = this.PagoService.GetErrorsCheckPago(input);
                return(BadRequest(errors));
            }

            DebtInputDataContract debt = await this.PagoService.GetDebtByUser(input.User_id);

            if (!this.PagoService.CheckAmountDebt(input, debt))
            {
                return(BadRequest("El monto del pago es superior al monto de la deuda."));
            }

            var pago = await this.PagoService.CreatePago(input, debt);

            return(StatusCode(StatusCodes.Status201Created, pago));
        }
コード例 #6
0
        public bool CheckAmountDebt(PagoInputDataContract pago, DebtInputDataContract debt)
        {
            decimal payment_Amount = GetLegalAmount(pago.Currency, pago.Amount);

            return((payment_Amount <= debt.Amount) ? true : false);
        }
コード例 #7
0
 public bool CheckInput(PagoInputDataContract input)
 {
     return(this.PagoInputDataContractValidator.Validate(input).IsValid);
 }