예제 #1
0
        public List <BorrowerInstallmentModel> AddBorrowerInstallment(BorrowerInstallmentModel installment)
        {
            List <BorrowerInstallmentModel> lstAllinstallments = new List <BorrowerInstallmentModel>();

            using (ShopDevEntities db = new ShopDevEntities())
            {
                try
                {
                    installment.BorrowerID = installment.BorrowerID == null ? 0 : installment.BorrowerID;
                    BorrowerInstallment borrowerinstDetail = null;
                    if (installment.InstallmentID > 0)
                    {
                        borrowerinstDetail = db.BorrowerInstallments.Where(m => m.InstallmentID == installment.InstallmentID).FirstOrDefault();
                    }
                    else
                    {
                        borrowerinstDetail = new BorrowerInstallment();
                    }
                    installment.CopyProperties(borrowerinstDetail);
                    if (borrowerinstDetail.InstallmentID == 0)
                    {
                        var borrower = db.Borrowers.Where(m => m.BorrowID == installment.BorrowerID).FirstOrDefault();
                        if (borrower.Amont > 0)
                        {
                            if (borrower.Interest != null && borrower.Interest != 0)
                            {
                                if (installment.Amount > borrower.Interest)
                                {
                                    var interest = borrower.Interest;
                                    borrower.Outstanding -= installment.Amount - interest;
                                    borrower.Interest     = 0;
                                    var interstableAmount = borrower.InterstableAmount;
                                    borrower.InterstableAmount     = interstableAmount == null? installment.Amount - interest: interstableAmount - (installment.Amount - interest);
                                    borrowerinstDetail.Description = "Amount cut for Interset" + Convert.ToString(interest) + " and adjust for amunt is " + Convert.ToString(installment.Amount - interest);
                                }
                                else
                                {
                                    borrower.Interest -= installment.Amount;
                                    borrowerinstDetail.Description = "Amount cut for Interset" + Convert.ToString(installment.Amount) + " and adjust for amunt is 0";
                                }
                            }
                            else
                            {
                                borrower.InterstableAmount    -= installment.Amount;
                                borrower.Outstanding          -= installment.Amount;
                                borrowerinstDetail.Description = "Amount cut for Interset 0 and adjust for amunt is " + Convert.ToString(installment.Amount);
                            }
                            borrower.LastInstallmentDate = DateTime.Now;
                            db.SaveChanges();
                        }
                        db.BorrowerInstallments.Add(borrowerinstDetail);
                    }
                    db.SaveChanges();
                    var lstinstallments = db.BorrowerInstallments.Where(m => m.BorrowerID == borrowerinstDetail.BorrowerID).ToList();
                    foreach (var cusprod in lstinstallments)
                    {
                        BorrowerInstallmentModel objcsproduct = new BorrowerInstallmentModel();
                        cusprod.CopyProperties(objcsproduct);
                        lstAllinstallments.Add(objcsproduct);
                    }
                }
                catch { }
                return(lstAllinstallments);
            }
        }