public ActionResult AddItem(Item item)
        {
            if (!ModelState.IsValid)
            {
                return(View(item));
            }

            {
            }

            if (item.ItemId == 0)
            {
                businessLogic = new BusinessLogic();
                businessLogic.AddItem(item);
            }
            else
            {
                var itemInDb = _context.items.SingleOrDefault(c => c.ItemId == item.ItemId);
                //create function on busineeslogic
                itemInDb.ItemName      = item.ItemName;
                itemInDb.ItemUnitPrice = item.ItemUnitPrice;
                itemInDb.DiscountRateOnUnitPrice.DiscountOnUnitPrice = item.DiscountRateOnUnitPrice.DiscountOnUnitPrice;
            }
            _context.SaveChanges();



            return(RedirectToAction("AddItem"));
        }
Beispiel #2
0
        //Irene
        public ActionResult Add()
        {
            //EVERYPAGE
            if (Session["user"] == null)
            {
                return(RedirectToAction("Login"));
            }
            Employee e = (Employee)Session["user"];

            if (e.RoleID != 3)
            {
                return(RedirectToAction("NotAuthorized"));
            }
            //EVERYPAGE

            ViewBag.user = e;
            String s = Request.Form["itemcode"];

            if (s != null)
            {
                decimal amount = 0;
                int     QtyNo  = Request.Form["qty"].Split(',').Count();
                //validation
                bool cancontinue = true; int i1, i2, i3; String itemcode; int errorrow = 0;
                for (int i = 0; i < QtyNo; i = i + BusinessLogic.getSupplierActive().Count)
                {
                    i1       = Convert.ToInt32(Request.Form["qty"].Split(',')[i]);
                    i2       = Convert.ToInt32(Request.Form["qty"].Split(',')[i + 1]);
                    i3       = Convert.ToInt32(Request.Form["qty"].Split(',')[i + 2]);
                    itemcode = s.Split(',')[i];
                    if (!CheckMin(i1, i2, i3, itemcode))
                    {
                        cancontinue = false; errorrow = i;
                    }
                }
                if (cancontinue)
                {
                    int oid = BusinessLogic.AddItem(e.EmployeeID);
                    for (int i = 0; i < QtyNo; i++)
                    {
                        BusinessLogic.AddItemDetail(oid, Request.Form["supplier"].Split(',')[i], s.Split(',')[i], Convert.ToInt32(Request.Form["qty"].Split(',')[i]));
                        amount = amount + Convert.ToInt32(Request.Form["qty"].Split(',')[i]) * Convert.ToDecimal(BusinessLogic.getCatalogueByID(s.Split(',')[i]).AveragePrice);
                    }
                    BusinessLogic.UpdateAmountByID(oid, amount);
                    Response.Redirect("./CreatePurchaseOrder");
                }
                else
                {
                    ViewBag.ugoterror = errorrow; Response.Redirect("./EditPurchaseOrder");
                }
            }
            return(View());
        }
Beispiel #3
0
        //Irene
        public ActionResult CreatePurchaseOrder()
        {
            //EVERYPAGE
            if (Session["user"] == null)
            {
                return(RedirectToAction("Login"));
            }
            Employee e = (Employee)Session["user"];

            if (e.RoleID != 3)
            {
                return(RedirectToAction("NotAuthorized"));
            }
            //EVERYPAGE

            ViewBag.user = e;
            String s = Request.Form["items"];

            if (s != null)
            {
                decimal amount = 0;
                int     QtyNo  = Request.Form["qty"].Split(',').Count();
                Response.Write(QtyNo);

                int oid = BusinessLogic.AddItem(e.EmployeeID);
                for (int i = 0; i < QtyNo; i++)
                {
                    if (Convert.ToInt32(Request.Form["qty"].Split(',')[i]) > 0)
                    {
                        BusinessLogic.AddItemDetail(oid, Request.Form["supplier"].Split(',')[i], s.Split(',')[i], Convert.ToInt32(Request.Form["qty"].Split(',')[i]));
                    }
                    amount = amount + Convert.ToInt32(Request.Form["qty"].Split(',')[i]) * Convert.ToDecimal(BusinessLogic.getCatalogueByID(s.Split(',')[i]).AveragePrice);
                }
                BusinessLogic.UpdateAmountByID(oid, amount);
            }
            ViewBag.amount = s;
            ViewBag.olist  = BusinessLogic.GetOrderCatalogue();

            return(View());
        }