public ActionResult ProductAddUpdate(int?id)
        {
            int ab = Convert.ToInt32(Session["id"]);
            int bc = Convert.ToInt32(Session["Designation"]);

            if (ab != 0 && bc == 2)
            {
                //ViewBag.ProductPlanId = new SelectList(db.ProductPlans, "ProductPlanId", "ProductName");
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                //Client ServiceAdd = db.Clients.Find(id);
                ProductBuying productBuying = db.ProductBuyings.Find(id);
                if (productBuying == null)
                {
                    return(HttpNotFound());
                }
                ViewBag.quantity      = productBuying.ProductQuantity;
                ViewBag.ProductPlanId = new SelectList(db.ProductPlans, "ProductPlanId", "ProductName");
                ViewBag.EmployeeId    = new SelectList(db.Employees, "EmployeeId", "EmployeeName");
                return(View(productBuying));
            }
            else
            {
                FormsAuthentication.SignOut();
                return(RedirectToAction("Login", "Login"));
            }
        }
예제 #2
0
        public ActionResult ProductAdd([Bind(Include = "productplanid,productquantity,prodyctbuyingdate,productexpiredate,productbuyparprice,productsellparprice,totalamount,employeeid")] ProductBuying productbuying, int?ProductPlanId, int?EmployeeId)
        {
            int er = 0;

            if (ProductPlanId == null)
            {
                er++;
                ViewBag.ProductPlanMessage = "ProductPlan Required";
            }
            //if (EmployeeId == null)
            //{
            //    er++;
            //    ViewBag.EmployeeMessage = "Employee Required";
            //}
            if (ModelState.IsValid)
            {
                int ab = Convert.ToInt32(Session["id"]);
                productbuying.EmployeeId = ab;

                //  db.SaveChanges();
                Storage storage = new Storage();
                storage.ProductPlanId = productbuying.ProductPlanId;
                //storage.ProductQuantity = productbuying.ProductQuantity;
                storage.ProductExpireDate = productbuying.ProductExpireDate;
                var productsearch = db.Storages.Where(x => x.ProductPlanId == productbuying.ProductPlanId).FirstOrDefault();
                if (productsearch == null)
                {
                    storage.ProductQuantity = productbuying.ProductQuantity;
                    db.Storages.Add(storage);
                    // db.Entry(storage).State = EntityState.Modified;
                    db.ProductBuyings.Add(productbuying);
                    db.SaveChanges();
                    return(RedirectToAction("ProductAddInfo"));

                    //return View(productbuying);
                }
                else
                {
                    int quantity        = productsearch.ProductQuantity;
                    int buyquantity     = productbuying.ProductQuantity;
                    int presentQuantity = quantity + buyquantity;
                    storage.ProductQuantity = presentQuantity;
                    storage.StorageId       = productsearch.StorageId;
                    // db.Storages.Add(storage);


                    db.ProductBuyings.Add(productbuying);

                    db.Entry(productsearch).State = EntityState.Detached;

                    db.Entry(storage).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("ProductAddInfo"));
                }
            }
            ViewBag.ProductPlanId = new SelectList(db.ProductPlans, "ProductPlanId", "ProductName");
            ViewBag.EmployeeId    = new SelectList(db.Employees, "EmployeeId", "EmployeeName");
            return(View(productbuying));
        }
        public ActionResult ProductAddUpdate([Bind(Include = "ProductButingId,ProductPlanId,ProductQuantity,ProdyctBuyingDate,ProductExpireDate,ProductBuyParPrice,productSellParPrice,TotalAmount,EmployeeId")] ProductBuying productBuying, int?quantity)
        {
            int     present_quantity  = 0;
            int     calculatequantity = 0;
            int     productplanid     = productBuying.ProductPlanId;
            var     storagequantity   = db.Storages.Where(x => x.ProductPlanId == productplanid).FirstOrDefault();
            Storage storage           = new Storage();

            if (quantity > productBuying.ProductQuantity)
            {
                int a = productBuying.ProductQuantity;
                int b = Convert.ToInt32(quantity);
                calculatequantity         = b - a;
                present_quantity          = storagequantity.ProductQuantity - calculatequantity;
                storage.ProductQuantity   = present_quantity; //present quantity
                storage.ProductExpireDate = productBuying.ProductExpireDate;
                storage.ProductPlanId     = productplanid;
                storage.StorageId         = storagequantity.StorageId;
            }
            else
            {
                int c = productBuying.ProductQuantity;
                int d = Convert.ToInt32(quantity);
                calculatequantity         = c - d;
                present_quantity          = storagequantity.ProductQuantity + calculatequantity;
                storage.ProductQuantity   = present_quantity;
                storage.ProductExpireDate = productBuying.ProductExpireDate;
                storage.ProductPlanId     = productplanid;
                storage.StorageId         = storagequantity.StorageId;
            }


            if (ModelState.IsValid)
            {
                db.Entry(storagequantity).State = EntityState.Detached;
                db.Entry(storage).State         = EntityState.Modified;

                db.Entry(productBuying).State = EntityState.Modified;
                db.SaveChanges();
                ViewBag.Message = "Data Update Successfully";
                return(RedirectToAction("ProductAddInfo"));
            }
            return(View(productBuying));
        }