Beispiel #1
0
 // installments
 public List<Installments> AddInstallment(Installments installment)
 {
     List<Installments> lstAllinstallments = new List<Installments>();
     using (ShopDevEntities db = new ShopDevEntities())
     {
         try
         {
             installment.BulkBuyID = installment.BulkBuyID == null ? 0 : installment.BulkBuyID;
             BulkBuyInstallment bulkinstDetail = null;
             if (installment.InstallmentID > 0)
             {
                 bulkinstDetail = db.BulkBuyInstallments.Where(m => m.InstallmentID == installment.InstallmentID).FirstOrDefault();
             }
             else
             {
                 bulkinstDetail = new BulkBuyInstallment();
             }
             installment.CopyProperties(bulkinstDetail);
             if (installment.InstallmentID == 0)
             {
                 var bulkBuy = db.BulkBuys.Where(m => m.BulkBuyID == installment.BulkBuyID).FirstOrDefault();
                 if (bulkBuy.InterstableAmount > 0)
                 {
                     if (bulkBuy.Interest != null && bulkBuy.Interest != 0)
                     {
                         if (installment.Amount > bulkBuy.Interest)
                         {
                             var interest = bulkBuy.Interest;
                             bulkBuy.OustandingAmont -= installment.Amount - interest;
                             bulkBuy.Interest = 0;
                             var interstableAmount = bulkBuy.InterstableAmount;
                             bulkBuy.InterstableAmount = interstableAmount == null ? installment.Amount - interest : interstableAmount - (installment.Amount - interest);
                             
                             bulkinstDetail.Description = "Amount cut for Interset" + Convert.ToString(interest) + " and adjust for amunt is " + Convert.ToString(installment.Amount - interest);
                         }
                         else
                         {
                             bulkBuy.Interest -= installment.Amount;
                             bulkinstDetail.Description = "Amount cut for Interset" + Convert.ToString(installment.Amount) + " and adjust for amunt is 0";
                         }
                     }
                     else
                     {
                         bulkBuy.OustandingAmont -= installment.Amount;
                         bulkBuy.InterstableAmount -= installment.Amount;
                         bulkinstDetail.Description = "Amount cut for Interset 0 and adjust for amunt is " + Convert.ToString(installment.Amount);
                     }
                     bulkBuy.LastInstallmentDate = DateTime.Now;
                     db.SaveChanges();
                 }
                 db.BulkBuyInstallments.Add(bulkinstDetail);
             }
             db.SaveChanges();
             var lstinstallments = db.BulkBuyInstallments.Where(m => m.BulkBuyID == installment.BulkBuyID).ToList();
             foreach (var cusprod in lstinstallments)
             {
                 Installments objcsproduct = new Installments();
                 cusprod.CopyProperties(objcsproduct);
                 lstAllinstallments.Add(objcsproduct);
             }
         }
         catch { }
         return lstAllinstallments;
     }
 }