public List<BulkBuyModel> AllBulk(BulkBuyModel bulkmodel) { List<BulkBuyModel> Allcust = new List<BulkBuyModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { var res = from buyer in db.BulkBuys where (buyer.CustomerName.Contains(bulkmodel.CustomerName) || buyer.CustomerCode == bulkmodel.CustomerCode) || (string.IsNullOrEmpty(bulkmodel.CustomerName) && bulkmodel.CustomerCode == null) select buyer; foreach (var seller in res) { BulkBuyModel sellerModel = new BulkBuyModel(); seller.CopyProperties(sellerModel); Allcust.Add(sellerModel); } } catch (Exception ex) { } return Allcust; } }
public BulkBuyViewModel GetBulk(long? bulkID) { BulkBuyViewModel bulkmodel = new BulkBuyViewModel(); using (ShopDevEntities db = new ShopDevEntities()) { try { var bulkBuycustomerInfo = db.BulkBuys.Where(m => m.BulkBuyID == bulkID).FirstOrDefault(); var lstproducts = db.BulkBuyProducts.Where(m => m.BulkBuyID == bulkID).ToList(); var AllInstallments = db.BulkBuyInstallments.Where(m => m.BulkBuyID == bulkID).ToList(); var Allvendors = db.VendorDetails.Where(m => m.BulkByID == bulkID).ToList(); BulkBuyModel bbModel = new BulkBuyModel(); bulkBuycustomerInfo.CopyProperties(bbModel); List<BulkBuyProductsModel> lstcsproducts = new List<BulkBuyProductsModel>(); foreach (var cusprod in lstproducts) { BulkBuyProductsModel objcsproduct = new BulkBuyProductsModel(); cusprod.CopyProperties(objcsproduct); lstcsproducts.Add(objcsproduct); } List<VendorDetailsModel> lstvendors = new List<VendorDetailsModel>(); foreach (var cusprod in Allvendors) { VendorDetailsModel objcsproduct = new VendorDetailsModel(); cusprod.CopyProperties(objcsproduct); lstvendors.Add(objcsproduct); } List<Installments> lstInstallments = new List<Installments>(); foreach (var cusprod in AllInstallments) { Installments objcsproduct = new Installments(); cusprod.CopyProperties(objcsproduct); lstInstallments.Add(objcsproduct); } bulkmodel.bulkBuyModel = bbModel; bulkmodel.Products = new BulkBuyProductsModel(); bulkmodel.lstbulkBuyProducts = new List<BulkBuyProductsModel>(); bulkmodel.lstbulkBuyProducts.AddRange(lstcsproducts); bulkmodel.Vendors = new VendorDetailsModel(); bulkmodel.lstVendors = new List<VendorDetailsModel>(); bulkmodel.lstVendors.AddRange(lstvendors); bulkmodel.installments = new Installments(); bulkmodel.lstinstallments = new List<Installments>(); bulkmodel.lstinstallments.AddRange(lstInstallments); } catch (Exception) { } } return bulkmodel; }
public void AddBulkBuy(BulkBuyModel BulkInfo) { using (ShopDevEntities db = new ShopDevEntities()) { try { if (BulkInfo.CustomerCode == null) { Customer customer = new Customer { CustmerName = BulkInfo.CustomerName, Address = BulkInfo.Address }; db.Customers.Add(customer); db.SaveChanges(); BulkInfo.CustomerCode = customer.CustCode; } var todayYear = DateTime.Now.Year; var CurrentMonth = DateTime.Now.Month; // calculation for interst if (BulkInfo.InterestRate != null && BulkInfo.InterestRate != 0) { var buyMonth = BulkInfo.StartDate.Value.Month; var buyYear = BulkInfo.StartDate.Value.Year; var monthDiff = ((todayYear - buyYear) * 12) + CurrentMonth - buyMonth; decimal? interst = 0; if (BulkInfo.InterstableAmount > 0) { interst = BulkInfo.InterstableAmount * BulkInfo.InterestRate * monthDiff / 100; } else { BulkInfo.InterstableAmount = BulkInfo.TakenAmount; interst = BulkInfo.TakenAmount * BulkInfo.InterestRate * monthDiff / 100; } BulkInfo.Interest = interst; BulkInfo.OustandingAmont = BulkInfo.TakenAmount + interst; } BulkBuy bulkbuy = null; if (BulkInfo.BulkBuyID == 0) { bulkbuy = new BulkBuy(); BulkInfo.CopyProperties(bulkbuy); db.BulkBuys.Add(bulkbuy); } else { bulkbuy = db.BulkBuys.Where(m => m.BulkBuyID == BulkInfo.BulkBuyID).FirstOrDefault(); BulkInfo.CopyProperties(bulkbuy); } db.SaveChanges(); List<BulkBuyProduct> lstNewproducts = db.BulkBuyProducts.Where(m => m.BulkBuyID == 0).ToList(); lstNewproducts.ForEach(m => m.BulkBuyID = bulkbuy.BulkBuyID); List<VendorDetail> lstvendors = db.VendorDetails.Where(m => m.BulkByID == 0).ToList(); lstvendors.ForEach(m => m.BulkByID = bulkbuy.BulkBuyID); List<BulkBuyInstallment> lstinstallments = db.BulkBuyInstallments.Where(m => m.BulkBuyID == 0).ToList(); lstinstallments.ForEach(m => m.BulkBuyID = bulkbuy.BulkBuyID); db.SaveChanges(); } catch { } } }