示例#1
0
        public async Task <DebtInputDataContract> GetDebtByUser(long user_Id)
        {
            string uri = this.AppSettings.Value.UrlAPICargos;

            string action = "api/Cargos/GetDebtByUser/";
            string id     = user_Id.ToString();

            DebtInputDataContract debt = new DebtInputDataContract();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(uri);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.GetAsync($"{action}{id}");

                if (response.IsSuccessStatusCode)
                {
                    var entity_Response = response.Content.ReadAsStringAsync().Result;

                    debt = JsonConvert.DeserializeObject <DebtInputDataContract>(entity_Response);
                }
            }

            return(debt);
        }
示例#2
0
        private async Task AddCargo(DebtInputDataContract debt, decimal payment_Amount, Pago pago)
        {
            foreach (var cargo in debt.Cargos)
            {
                if (payment_Amount == 0)
                {
                    break;
                }

                Constancia constancia = new Constancia()
                {
                    Cargo_Id = cargo.Cargo_Id,
                };

                if (payment_Amount >= cargo.Amount)
                {
                    constancia.Amount = cargo.Amount;

                    payment_Amount -= cargo.Amount;
                    cargo.Amount    = 0;
                }
                else
                {
                    constancia.Amount = payment_Amount;

                    cargo.Amount  -= payment_Amount;
                    payment_Amount = 0;
                }

                if (await this.UpdateCargo(constancia))
                {
                    pago.Constancias.Add(constancia);
                }
            }
        }
示例#3
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));
        }
示例#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 bool CheckAmountDebt(PagoInputDataContract pago, DebtInputDataContract debt)
        {
            decimal payment_Amount = GetLegalAmount(pago.Currency, pago.Amount);

            return((payment_Amount <= debt.Amount) ? true : false);
        }