public IList <HouseLoanModel> GetHouseLoanList(int UserId) { IList <HouseLoanModel> listitems = new List <HouseLoanModel>(); try { using (SqlConnection conn = new SqlConnection(ContexDetails.Connectiondetails())) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "sp_GetHouseLoanRequested"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserId", UserId); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { HouseLoanModel model = new HouseLoanModel(); 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); }
public int AddHouseLoanDetails(HouseLoanModel model) { int Id = 0; try { using (SqlConnection conn = new SqlConnection(ContexDetails.Connectiondetails())) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "sp_AddHouseLoanDetails"; 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); }