/// <summary> /// Get Installment /// Create the InstallmentDetails: /// - initial the InstallmentDetail Lists countOf(numberOfMonths) /// - Fill the DueToPay each InstallmentDetail /// - Fill the PaymentDate to 1/1/1755 date as they not payed /// - Save To the database /// </summary> public static void CreateAndSaveInstallmentDetailsToTheDatabase(InstallmentModel installment, string db) { installment.InstallmentDetails = new List <InstallmentDetailsModel>(); DateTime paymentDate = new DateTime(); paymentDate = installment.PaymentsStartDate; for (int i = 1; i <= installment.NumberOfMonths; i++) { InstallmentDetailsModel installmentDetails = new InstallmentDetailsModel(); installmentDetails.DueToPay = paymentDate; installmentDetails.PaymentDate = new DateTime(1755, 1, 1); installment.InstallmentDetails.Add(installmentDetails); paymentDate = paymentDate.AddMonths(1); } using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db))) { foreach (InstallmentDetailsModel installmentDetailsModel in installment.InstallmentDetails) { var o = new DynamicParameters(); o.Add("@InstallmentId", installment.Id); o.Add("@DuoToPay", installmentDetailsModel.DueToPay); o.Add("@PaymentDate", installmentDetailsModel.PaymentDate); connection.Execute("dbo.spInstallmentDetails_Create", o, commandType: CommandType.StoredProcedure); } } }
/// <summary> /// Foreach InstallmentProduct in The Installment , save it in the database /// </summary> /// <param name="installment"></param> /// <param name="db"></param> public static void SaveInstallmentProductToTheDatabase(InstallmentModel installment, string db) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db))) { foreach (InstallmentProductModel installmentProduct in installment.Products) { var o = new DynamicParameters(); o.Add("@InstallmentId", installment.Id); o.Add("@ProductId", installmentProduct.Product.Id); o.Add("@Quantity", installmentProduct.Quantity); o.Add("@InstallmentPrice", installmentProduct.InstallmentPrice); o.Add("@Discount", installmentProduct.Discount); connection.Execute("dbo.spInstallmentProduct_Create", o, commandType: CommandType.StoredProcedure); } } }
/// <summary> /// Create installment to the database /// requires : CustomerModel,Date,NumberOfMonths,PaymentsStartDate,EMI,RateOfInterest,LoanAmount,Deposit,TotalInstallmentPrice,StoreModel,StaffModel /// </summary> /// <param name="installment"></param> /// <param name="db"></param> /// <returns></returns> public static InstallmentModel GetEmptyInstallmentFromTheDatabase(InstallmentModel installment, string db) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db))) { var p = new DynamicParameters(); p.Add("@CustomerId", installment.Customer.Id); p.Add("@Date", installment.Date); p.Add("@NumberOfMonths", installment.NumberOfMonths); p.Add("@PaymentsStartsDate", installment.PaymentsStartDate); p.Add("@EMI", installment.EMI); p.Add("@RateOfInterest", installment.RateOfInterest); p.Add("@LoanAmount", installment.LoanAmount); p.Add("@Deposit", installment.Deposit); p.Add("@TotalInstallmentPrice", installment.TotaInstallmentPrice); p.Add("@StoreId", installment.Store.Id); p.Add("@StaffId", installment.Staff.Id); p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); connection.Execute("dbo.spInstallment_Create", p, commandType: CommandType.StoredProcedure); installment.Id = p.Get <int>("@Id"); } return(installment); }