Ejemplo n.º 1
0
        public ActionResult Create(SaleItem saleItem)
        {
            if (ModelState.IsValid)
            {
                SaleItem SI;                                                                    // Create new SaleItem and set it equal to the SaleItem that was passed in
                SI = saleItem;
                Inventory inv;                                                                  // Get information from Inventory table
                inv          = db.Inventories.Find(SI.ProductID);                               // Set Inventory information equal to the SaleItem ProductID
                SI.Inventory = inv;
                Sale s;                                                                         // Get information from Sale table
                s           = db.Sales.Find(Int32.Parse(Session["Current SaleID"].ToString())); // Set s equal to the Current SaleID
                SI.Sale     = s;
                SI.Returned = 0;                                                                // Returned = 0 because a transaction is being performed. (Not returning)
                SI.SaleID   = s.SaleID;                                                         // added
                SI.TotalSI += SI.Quantity;                                                      // Total of items added at one time
                if (SI.Inventory != null)
                {
                    SI.Inventory.Quantity -= SI.Quantity;
                }
                if (inv != null)
                {
                    SI.TotalSIPrice += SI.Quantity * (double)inv.SalePrice;  // Total sale price of item specified
                }
                //SI.Sale.TotalSaleItems += SI.TotalSI;
                //SI.Sale.TotalSalePrice += SI.TotalSIPrice;
                db.SaleItems.Add(SI);
                db.SaveChanges();
                return(RedirectToAction("Create", new { id = s.SaleID.ToString() })); // URL ID equal to the Current SaleID
            }

            ViewBag.ProductID = new SelectList(db.Inventories, "ProductID", "ProductID", saleItem.ProductID);
            ViewBag.SaleID    = new SelectList(db.Sales, "SaleID", "SaleID", saleItem.SaleID);
            return(View(saleItem));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "POItemID,ProductID,Quantity,Received,PurchaseOrderID")] PurchaseOrderItem purchaseOrderItem)
        {
            if (ModelState.IsValid)
            {
                // Instantiate foreign key field for Inventory
                PurchaseOrderItem ans;
                ans = purchaseOrderItem;
                _540GPWorkingBuild.Models.Inventory inv;
                inv           = db.Inventories.Find(Int32.Parse(Request["ProductID"].ToString()));
                ans.Inventory = inv;


                //Instantiate foreign key for PurchaseOrder
                _540GPWorkingBuild.Models.PurchaseOrder po;
                po = db.PurchaseOrders.Find(Int32.Parse(Session["currPo"].ToString()));
                ans.PurchaseOrder = po;

                // Set initial received value to zero
                ans.Received = 0;

                // Save database
                db.PurchaseOrderItems.Add(ans);
                db.SaveChanges();

                // Bounce user to the detail page for the purchase order
                return(RedirectToAction("Details", "PurchaseOrders", new { id = po.PurchaseOrderID.ToString() }));
            }

            ViewBag.ProductID       = new SelectList(db.Inventories, "ProductID", "Name", purchaseOrderItem.ProductID);
            ViewBag.PurchaseOrderID = new SelectList(db.PurchaseOrders, "PurchaseOrderID", "PurchaseOrderID", purchaseOrderItem.PurchaseOrderID);
            return(View(purchaseOrderItem));
        }
        public ActionResult Create(SaleItem saleItem)
        {
            if (ModelState.IsValid)
            {
                SaleItem SI;
                SI = saleItem;
                Inventory inv;
                inv          = db.Inventories.Find(SI.ProductID);
                SI.Inventory = inv;
                Sale s;
                s           = db.Sales.Find(Int32.Parse(Session["Current SaleID"].ToString()));
                SI.Sale     = s;
                SI.Returned = 0;
                SI.SaleID   = s.SaleID;   // added
                //SI.TotalSI += SI.Quantity;
                //SI.TotalSIPrice = SI.Quantity * (double)inv.SalePrice;
                //SI.Sale.TotalSaleItems += SI.TotalSI;
                //SI.Sale.TotalSalePrice += SI.TotalSIPrice;
                db.SaleItems.Add(SI);
                db.SaveChanges();
                return(RedirectToAction("Create", new { id = s.SaleID.ToString() }));
            }

            ViewBag.ProductID = new SelectList(db.Inventories, "ProductID", "ProductID", saleItem.ProductID);
            ViewBag.SaleID    = new SelectList(db.Sales, "SaleID", "SaleID", saleItem.SaleID);
            return(View(saleItem));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "AddressID,StreetAddress,AptNumber,City,State,ZipCode")] Address address)
        {
            if (ModelState.IsValid)
            {
                db.Addresses.Add(address);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(address));
        }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "RoleID,EmpRole")] EmployeeRole employeeRole)
        {
            if (ModelState.IsValid)
            {
                db.EmployeeRoles.Add(employeeRole);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employeeRole));
        }
Ejemplo n.º 6
0
        public ActionResult Create([Bind(Include = "CategoryID,Category1,Active")] Category category)
        {
            if (ModelState.IsValid)
            {
                category.Active = 1;
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
        public ActionResult Create([Bind(Include = "CustomerID,FirstName,LastName,AddressID,Email,PhoneNum,Active")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AddressID = new SelectList(db.Addresses, "AddressID", "StreetAddress", customer.AddressID);
            return(View(customer));
        }
Ejemplo n.º 8
0
        public ActionResult Create([Bind(Include = "ProductID,Name,Description,NetPrice,SalePrice,Quantity,CategoryID,Active")] Inventory inventory)
        {
            if (ModelState.IsValid)
            {
                inventory.Active = 1;
                db.Inventories.Add(inventory);
                db.SaveChanges();
                return(RedirectToAction("Products"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Category1", inventory.CategoryID);
            return(View(inventory));
        }
        public ActionResult Create([Bind(Include = "EmployeeID,FirstName,LastName,HireDate,RoleID,PhoneNum,AddressID,Email,Password,Active")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AddressID = new SelectList(db.Addresses, "AddressID", "StreetAddress", employee.AddressID);
            ViewBag.RoleID    = new SelectList(db.EmployeeRoles, "RoleID", "EmpRole", employee.RoleID);
            return(View(employee));
        }
        public ActionResult Create([Bind(Include = "EmployeeID,FirstName,LastName,HireDate,RoleID,PhoneNum,AddressID,Email,Password,Active")] Employee employee)
        {
            if (!(Session["UserRole"].Equals("Manager") || Session["UserRole"].Equals("Admin")))
            {
                return(RedirectToAction("LowPermission"));
            }
            if (ModelState.IsValid)
            {
                employee.Active = 1;
                db.Employees.Add(employee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AddressID = new SelectList(db.Addresses, "AddressID", "StreetAddress", employee.AddressID);
            ViewBag.RoleID    = new SelectList(db.EmployeeRoles, "RoleID", "EmpRole", employee.RoleID);
            return(View(employee));
        }
Ejemplo n.º 11
0
        public ActionResult Create([Bind(Include = "CustomerID,FirstName,LastName,AddressID,Email,PhoneNum,Active")] Customer customer)
        {
            if (!(Session["UserRole"].Equals("Manager") || Session["UserRole"].Equals("Admin")))
            {
                return(RedirectToAction("LowPerm"));
            }

            if (ModelState.IsValid)
            {
                customer.Active = 1;
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AddressID = new SelectList(db.Addresses, "AddressID", "StreetAddress", customer.AddressID);
            return(View(customer));
        }
Ejemplo n.º 12
0
        // Get a poWithItems object based on a given purchase order ID and db instance
        public poWithItems getOrderWithItems(int givenID, MusciToolkitDBEntities dbInstance)
        {
            var ansPO   = db.PurchaseOrders.SingleOrDefault(x => x.PurchaseOrderID == givenID);
            var ansList = db.PurchaseOrderItems.Where(x => x.PurchaseOrderID == givenID);

            // Declare total line price for each PurchaseOrderItem in the list.. Shoutout to Luke!!
            foreach (var each in ansList)
            {
                double currLineCost = (double)each.Quantity * (double)each.Inventory.NetPrice;
                each.totalPrice = currLineCost;
            }
            db.SaveChanges();
            var ans = new poWithItems(ansPO, ansList);

            poTotalSet(ans);
            return(ans);
        }
Ejemplo n.º 13
0
        public soWithItems getOrderWithItems(int givenID, MusciToolkitDBEntities dbInstance)
        {
            var ansSO        = db.Sales.SingleOrDefault(x => x.SaleID == givenID);
            var ansList      = db.SaleItems.Where(x => x.SaleID == givenID);
            int currLineItem = 0;

            //double currLineCost = 0;
            foreach (var each in ansList)
            {
                double currLineCost = each.Quantity * (double)each.Inventory.SalePrice;
                currLineItem       = each.Quantity;
                each.TotalSIPrice += currLineCost;
                each.TotalSI       = currLineItem;
            }
            db.SaveChanges();
            var ans = new soWithItems(ansSO, ansList);

            soTotalSet(ans);
            db.SaveChanges();
            return(ans);
        }