public async Task <ActionResult <FundingInterestRate> > GetFundingInterestRate([DataSourceRequest] DataSourceRequest request, Int64 FundingInterestRateId)
        {
            FundingInterestRate _FundingInterestRatep = new FundingInterestRate();

            try
            {
                string     baseadress = config.Value.urlbase;
                HttpClient _client    = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                var result = await _client.GetAsync(baseadress + "api/FundingInterestRate/GetFundingInterestRateById/" + FundingInterestRateId);

                string valorrespuesta = "";
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta        = await(result.Content.ReadAsStringAsync());
                    _FundingInterestRatep = JsonConvert.DeserializeObject <FundingInterestRate>(valorrespuesta);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                throw ex;
            }



            return(_FundingInterestRatep);
        }
        //[ValidateAntiForgeryToken]
        public async Task <ActionResult> Insert(FundingInterestRate _FundingInterestRateP)
        {
            FundingInterestRate _FundingInterestRate = _FundingInterestRateP;

            try
            {
                string     baseadress = config.Value.urlbase;
                HttpClient _client    = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                _FundingInterestRate.UsuarioCreacion     = HttpContext.Session.GetString("user");
                _FundingInterestRate.UsuarioModificacion = HttpContext.Session.GetString("user");
                var result = await _client.PostAsJsonAsync(baseadress + "api/FundingInterestRate/Insert", _FundingInterestRate);

                string valorrespuesta = "";
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta       = await(result.Content.ReadAsStringAsync());
                    _FundingInterestRate = JsonConvert.DeserializeObject <FundingInterestRate>(valorrespuesta);
                }
            }
            catch (Exception ex)
            {
                return(BadRequest($"Ocurrio un error{ex.Message}"));
            }
            //return Ok(_FundingInterestRate);
            return(new ObjectResult(new DataSourceResult {
                Data = new[] { _FundingInterestRate }, Total = 1
            }));
        }
        public async Task <ActionResult <FundingInterestRate> > Delete([FromBody] FundingInterestRate _FundingInterestRate)
        {
            try
            {
                string     baseadress = config.Value.urlbase;
                HttpClient _client    = new HttpClient();
                _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));

                var result = await _client.PostAsJsonAsync(baseadress + "api/FundingInterestRate/Delete", _FundingInterestRate);

                string valorrespuesta = "";
                if (result.IsSuccessStatusCode)
                {
                    valorrespuesta       = await(result.Content.ReadAsStringAsync());
                    _FundingInterestRate = JsonConvert.DeserializeObject <FundingInterestRate>(valorrespuesta);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error: {ex.Message}"));
            }



            //return Ok(_VendorType);
            return(new ObjectResult(new DataSourceResult {
                Data = new[] { _FundingInterestRate }, Total = 1
            }));
        }
        public async Task <IActionResult> GetFundingInterestRateById(int Id)
        {
            FundingInterestRate Items = new FundingInterestRate();

            try
            {
                Items = await _context.FundingInterestRate.Where(q => q.Id.Equals(Id)).FirstOrDefaultAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            return(await Task.Run(() => Ok(Items)));
        }
        public async Task <ActionResult <FundingInterestRate> > Insert([FromBody] FundingInterestRate payload)
        {
            FundingInterestRate FundingInterestRate = payload;

            try
            {
                _context.FundingInterestRate.Add(FundingInterestRate);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(BadRequest($"Ocurrio un error:{ex.Message}"));
            }

            return(await Task.Run(() => Ok(FundingInterestRate)));
        }
        public async Task <IActionResult> Delete([FromBody] FundingInterestRate payload)
        {
            FundingInterestRate FundingInterestRate = new FundingInterestRate();

            try
            {
                FundingInterestRate = _context.FundingInterestRate
                                      .Where(x => x.Id == (int)payload.Id)
                                      .FirstOrDefault();
                _context.FundingInterestRate.Remove(FundingInterestRate);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}")));
            }

            return(await Task.Run(() => Ok(FundingInterestRate)));
        }
        public async Task <ActionResult <FundingInterestRate> > Update([FromBody] FundingInterestRate _FundingInterestRate)
        {
            try
            {
                FundingInterestRate FundingInterestRateq = (from c in _context.FundingInterestRate
                                                            .Where(q => q.Id == _FundingInterestRate.Id)
                                                            select c
                                                            ).FirstOrDefault();

                _FundingInterestRate.FechaCreacion   = FundingInterestRateq.FechaCreacion;
                _FundingInterestRate.UsuarioCreacion = FundingInterestRateq.UsuarioCreacion;

                _context.Entry(FundingInterestRateq).CurrentValues.SetValues((_FundingInterestRate));
                // _context.FundingInterestRate.Update(_FundingInterestRate);
                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}")));
            }

            return(await Task.Run(() => Ok(_FundingInterestRate)));
        }
        public async Task <ActionResult <FundingInterestRate> > SaveFundingInterestRate([FromBody] FundingInterestRateDTO _FundingInterestRateS)
        {
            {
                string valorrespuesta = "";
                try
                {
                    FundingInterestRate _listVendorType = new FundingInterestRate();
                    string     baseadress = config.Value.urlbase;
                    HttpClient _client    = new HttpClient();
                    _client.DefaultRequestHeaders.Add("Authorization", "Bearer " + HttpContext.Session.GetString("token"));
                    var result = await _client.GetAsync(baseadress + "api/FundingInterestRate/GetFundingInterestRateByDescripcion/" + _FundingInterestRateS.Descripcion);

                    if (result.IsSuccessStatusCode)
                    {
                        valorrespuesta  = await(result.Content.ReadAsStringAsync());
                        _listVendorType = JsonConvert.DeserializeObject <FundingInterestRate>(valorrespuesta);
                        if (_listVendorType != null && _FundingInterestRateS.Id == 0)
                        {
                            if (_listVendorType.Descripcion == _FundingInterestRateS.Descripcion)
                            {
                                result = await _client.GetAsync(baseadress + "api/FundingInterestRate/GetFundingInterestRateByMonths/" + _FundingInterestRateS.Months);

                                if (result.IsSuccessStatusCode)
                                {
                                    valorrespuesta  = await(result.Content.ReadAsStringAsync());
                                    _listVendorType = JsonConvert.DeserializeObject <FundingInterestRate>(valorrespuesta);
                                    if (_listVendorType != null && _FundingInterestRateS.Id == 0)
                                    {
                                        if (_listVendorType.Months == _FundingInterestRateS.Months)
                                        {
                                            return(await Task.Run(() => BadRequest($"Ya existe una tasa de interes registrada con ese mes.")));
                                        }
                                    }
                                }
                            }
                        }
                    }



                    result = await _client.GetAsync(baseadress + "api/FundingInterestRate/GetFundingInterestRateById/" + _FundingInterestRateS.Id);

                    _FundingInterestRateS.FechaModificacion   = DateTime.Now;
                    _FundingInterestRateS.UsuarioModificacion = HttpContext.Session.GetString("user");
                    if (result.IsSuccessStatusCode)
                    {
                        valorrespuesta  = await(result.Content.ReadAsStringAsync());
                        _listVendorType = JsonConvert.DeserializeObject <FundingInterestRate>(valorrespuesta);
                    }

                    if (_listVendorType == null)
                    {
                        _listVendorType = new Models.FundingInterestRate();
                    }

                    if (_listVendorType.Id == 0)
                    {
                        _FundingInterestRateS.FechaCreacion   = DateTime.Now;
                        _FundingInterestRateS.UsuarioCreacion = HttpContext.Session.GetString("user");
                        var insertresult = await Insert(_FundingInterestRateS);
                    }
                    else
                    {
                        _FundingInterestRateS.FechaCreacion   = DateTime.Now;
                        _FundingInterestRateS.UsuarioCreacion = HttpContext.Session.GetString("user");
                        var updateresult = await Update(_FundingInterestRateS.Id, _FundingInterestRateS);
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Ocurrio un error: { ex.ToString() }");
                    throw ex;
                }

                return(Json(_FundingInterestRateS));
            }
        }