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