public ActionResult DeleteConfirmed(long id)
        {
            BulkBuy bulkBuy = db.BulkBuys.Find(id);

            db.BulkBuys.Remove(bulkBuy);
            db.SaveChanges();
            TempData["Message"] = "Bulk deleted Successfully !";
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "BulkBuyID,CustomerName,Address,TakenAmount,Rate,GWeight,SWeight,Status")] BulkBuy bulkBuy)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bulkBuy).State = EntityState.Modified;
         db.SaveChanges();
         TempData["Message"] = "Bulk updated Successfully !";
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductTypeID = new SelectList(db.ProductTypes, "TypeName", "TypeName");
     return(View(bulkBuy));
 }
        // GET: BulkBuys/Details/5
        public ActionResult Details(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BulkBuy bulkBuy = db.BulkBuys.Find(id);

            if (bulkBuy == null)
            {
                return(HttpNotFound());
            }
            return(View(bulkBuy));
        }
        public IActionResult New(CreateVm model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var bulkBuy = new BulkBuy()
            {
                DisplayId   = _shortCodeService.GenerateId(IdPrefix.BULK_BUY),
                Name        = model.Name,
                Description = model.Description,
                DueDate     = model.ClosingDate,
                OwnerId     = _userManager.GetUserId(User),
                CreatedDate = DateTime.UtcNow
            };

            _context.BulkBuys.Add(bulkBuy);
            _context.SaveChanges();

            return(RedirectToAction("Details", new { id = bulkBuy.DisplayId }));
        }
示例#5
0
        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
                {

                }
            }
        }