Ejemplo n.º 1
0
        public int Add(Entities.Models.LoanConsultation value)
        {
            using (SqlCommand cmd = new SqlCommand("dbo.LoanConsultation_Add", Connection.Cnn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Age", value.Age));
                cmd.Parameters.Add(new SqlParameter("@Amount", value.Amount));
                cmd.Parameters.Add(new SqlParameter("@Months", value.Months));
                cmd.Parameters.Add(new SqlParameter("@AmountFee", value.AmountFee));
                cmd.Parameters.Add(new SqlParameter("@IPClient", value.IPClient));

                try
                {
                    if (Connection.Cnn.State == ConnectionState.Closed)
                    {
                        Connection.Cnn.Open();
                    }

                    return((int)(cmd.ExecuteScalar()));
                }
                catch (SqlException ex)
                {
                    return(0);

                    throw new Exception("Error ", ex);
                }
                finally
                {
                    if (Connection.Cnn.State == ConnectionState.Open)
                    {
                        Connection.Cnn.Close();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public List <Entities.Models.LoanConsultation> GetAll()
        {
            using (SqlCommand cmd = new SqlCommand("dbo.LoanConsultation_GetAll", Connection.Cnn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                IDataReader drResult = null;
                List <Entities.Models.LoanConsultation> records = new List <Entities.Models.LoanConsultation>();

                try
                {
                    if (Connection.Cnn.State == ConnectionState.Closed)
                    {
                        Connection.Cnn.Open();
                    }

                    drResult = cmd.ExecuteReader();
                    while (drResult.Read())
                    {
                        Entities.Models.LoanConsultation record = new Entities.Models.LoanConsultation();
                        record.ConsultationId = (int)(drResult["ConsultationId"]);
                        record.Registered     = (DateTime)(drResult["Registered"]);
                        record.Age            = (int)(drResult["Age"]);
                        record.Amount         = (decimal)(drResult["Amount"]);
                        record.Months         = (int)(drResult["Months"]);
                        record.AmountFee      = (decimal)(drResult["AmountFee"]);
                        record.IPClient       = (String)(drResult["IPClient"]);


                        records.Add(record);
                    }

                    return(records);
                }
                catch (SqlException ex)
                {
                    return(records);

                    throw new Exception("Error ", ex);
                }
                finally
                {
                    if (Connection.Cnn.State == ConnectionState.Open)
                    {
                        Connection.Cnn.Close();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public Entities.Models.LoanConsultation GetByGUID(string value)
        {
            using (SqlCommand cmd = new SqlCommand("dbo.LoanConsultation_GetByGUID", Connection.Cnn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@value", value));
                IDataReader drResult = null;
                Entities.Models.LoanConsultation record = null;

                try
                {
                    if (Connection.Cnn.State == ConnectionState.Closed)
                    {
                        Connection.Cnn.Open();
                    }

                    drResult = cmd.ExecuteReader();
                    if (drResult.Read())
                    {
                        record = new Entities.Models.LoanConsultation();
                        record.ConsultationId = (int)(drResult["ConsultationId"]);
                        record.Registered     = (DateTime)(drResult["Registered"]);
                        record.Age            = (int)(drResult["Age"]);
                        record.Amount         = (decimal)(drResult["Amount"]);
                        record.Months         = (int)(drResult["Months"]);
                        record.AmountFee      = (decimal)(drResult["AmountFee"]);
                        record.IPClient       = (String)(drResult["IPClient"]);
                    }

                    return(record);
                }
                catch (SqlException ex)
                {
                    return(record);

                    throw new Exception("Error ", ex);
                }
                finally
                {
                    if (Connection.Cnn.State == ConnectionState.Open)
                    {
                        Connection.Cnn.Close();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult getCalculationFee(Calculate value)
        {
            try
            {
                // Checking ege, if the client is elegible, comment will be empty,
                // otherwise this method will return a message according to age.
                Entities.DTO.Elegible Eligibility = Business.LoanBook.GetCommenFoElegible(value.DateOfBirth);

                // If client is elegible, calculate fee and save consultation.
                decimal calclatedFee = Business.LoanBook.CalculationFee(value.Amount, value.RateValue, value.MonthValue);

                // Save consultation log
                var consultation = new Entities.Models.LoanConsultation()
                {
                    Age       = Eligibility.Age,
                    Amount    = value.Amount,
                    Months    = value.MonthValue,
                    AmountFee = calclatedFee,
                    IPClient  = value.IPClient
                };

                int result = Business.LoanConsultation.Add(consultation);
                if (result != 0)
                {
                    return(Eligibility.IsElegible == false?
                           BadRequest(Eligibility.Comment) :
                               (IHttpActionResult)Ok(calclatedFee));
                }
                else
                {
                    return(BadRequest("No se pudo obtener la cuota."));
                }
            }
            catch (Exception ex)
            {
                _ = ex.Message;
                return(BadRequest("Ha ocurrido un error."));
            }
        }
Ejemplo n.º 5
0
 public static int Add(Entities.Models.LoanConsultation value)
 {
     return(obj.Add(value));
 }
Ejemplo n.º 6
0
 public static int Edit(Entities.Models.LoanConsultation value)
 {
     return(obj.Edit(value));
 }