Example #1
0
        public IList <PersonalLoanModel> GetPersonalLoanList(int UserId)
        {
            IList <PersonalLoanModel> listitems = new List <PersonalLoanModel>();

            try
            {
                using (SqlConnection conn = new SqlConnection(ContexDetails.Connectiondetails()))
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "sp_GetPersonalLoanRequested";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@UserId", UserId);
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                PersonalLoanModel model = new PersonalLoanModel();
                                model.LoanAmount     = Convert.ToString(reader["LoanAmount"]);
                                model.LoanTenure     = Convert.ToString(reader["LoanTenure"]);
                                model.RateOfInterest = Convert.ToString(reader["RateOfInterest"]);
                                model.CreatedDate    = Convert.ToDateTime(reader["CreatedDate"]);
                                listitems.Add(model);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(listitems);
        }
Example #2
0
        public int AddPersonalLoanDetails(PersonalLoanModel model)
        {
            int Id = 0;

            try
            {
                using (SqlConnection conn = new SqlConnection(ContexDetails.Connectiondetails()))
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "sp_AddPersonalLoanDetails";
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@LoanAmount", model.LoanAmount);
                        cmd.Parameters.AddWithValue("@LoanTenure", model.LoanTenure);
                        cmd.Parameters.AddWithValue("@RateOfInterest", model.RateOfInterest);
                        cmd.Parameters.AddWithValue("@CreatedBy", model.CreatedBy);
                        cmd.Parameters.Add("@Result", SqlDbType.Int).Direction = ParameterDirection.Output;
                        int i = cmd.ExecuteNonQuery();
                        Id = Convert.ToInt32(cmd.Parameters["@Result"].Value);
                    }
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(Id);
        }
Example #3
0
 public IActionResult Calculate(PersonalLoanModel data)
 {
     if (IsModelValid(out var errors))
     {
         return(Ok(new ResponseModel <LoanCalculationsModel>
         {
             Data = mapper.Map <LoanCalculationsModel>(
                 loanCalculator.Calculate(mapper.Map <PersonalLoan>(data)))
         }));
     }
     else
     {
         return(new ObjectResult(new ResponseModel {
             Errors = errors
         })
         {
             StatusCode = (int?)HttpStatusCode.BadRequest
         });
     }
 }
Example #4
0
        public IActionResult Create([FromBody] PersonalLoanModel loan)
        {
            if (IsModelValid(out var errors))
            {
                PersonalLoan addedLoan = loansRepository.Add(mapper.Map <PersonalLoan>(loan));

                return(new CreatedResult(nameof(LoansController.Get), new ResponseModel <PersonalLoanModel> {
                    Data = mapper.Map <PersonalLoanModel>(addedLoan)
                }));
            }
            else
            {
                return(new ObjectResult(new ResponseModel {
                    Errors = errors
                })
                {
                    StatusCode = (int?)HttpStatusCode.BadRequest
                });
            }
        }
        public void CreateTest()
        {
            PersonalLoanModel personalLoanModel = CreatePersonalLoanModel();
            var personalLoan = new PersonalLoan(PersonalLoanName, 1, 1, 1, Payback.EveryMonth, PersonalLoanId);

            mapperMock.Setup(m => m.Map <PersonalLoan>(personalLoanModel)).Returns(personalLoan);
            loansRepositoryMock.Setup(m => m.Add(personalLoan)).Returns(personalLoan);
            mapperMock.Setup(m => m.Map <PersonalLoanModel>(personalLoan)).Returns(personalLoanModel);

            var expectedResponse = new ResponseModel <PersonalLoanModel>()
            {
                Data = personalLoanModel
            };
            var expected = new CreatedResult(nameof(LoansController.Get), expectedResponse);
            var actual   = loansController.Create(expectedResponse.Data);

            Assert.Equal(
                expected,
                (CreatedResult)actual,
                GetActionResultResponsePersonalLoanModelComparer()
                );
        }
        public void CalculateLoanTest()
        {
            PersonalLoanModel personalLoanModel = CreatePersonalLoanModel();
            var personalLoan = new PersonalLoan(PersonalLoanName, 1, 1, 1, Payback.EveryMonth);

            mapperMock.Setup(m => m.Map <PersonalLoan>(personalLoanModel)).Returns(personalLoan);

            var loanCalculations  = new LoanCalculations(1, 1, 1);
            var expectedLoanValue = new LoanCalculationsModel {
                Total = 100
            };

            mapperMock.Setup(m => m.Map <LoanCalculationsModel>(loanCalculations)).Returns(expectedLoanValue);

            calculatorMock.Setup(c => c.Calculate(personalLoan)).Returns(loanCalculations);
            var response = loansController.Calculate(personalLoanModel);
            var actual   = (ResponseModel <LoanCalculationsModel>)((ObjectResult)response).Value;
            var expected = new ResponseModel <LoanCalculationsModel> {
                Data = expectedLoanValue
            };

            Assert.Equal(expected.Data, actual.Data);
        }
        public void GetTest()
        {
            PersonalLoanModel personalLoanModel = CreatePersonalLoanModel();
            var personalLoan = new PersonalLoan(PersonalLoanName, 1, 1, 1, Payback.EveryMonth, PersonalLoanId);

            mapperMock.Setup(m => m.Map <PersonalLoanModel>(personalLoan)).Returns(personalLoanModel);
            loansRepositoryMock.Setup(m => m.Get(PersonalLoanId)).Returns(personalLoan);
            var expectedResponse = new ResponseModel <PersonalLoanModel>()
            {
                Data = personalLoanModel
            };
            var expected = new ObjectResult(expectedResponse)
            {
                StatusCode = (int)HttpStatusCode.OK
            };

            var actual = loansController.Get(PersonalLoanId);

            Assert.Equal(
                expected,
                (ObjectResult)actual,
                GetActionResultResponsePersonalLoanModelComparer()
                );
        }