Exemplo n.º 1
0
        public ActionResult Login(Models.Employee e)
        {
            if (ModelState.IsValid)
            {
                using (MusciToolkitDBEntities db = new MusciToolkitDBEntities())
                {
                    var obj = db.Employees.Where(a => a.EmployeeID.Equals(e.EmployeeID) && a.Password.Equals(e.Password)).FirstOrDefault();
                    if (obj != null)
                    {
                        Session["UserID"] = obj.EmployeeID.ToString();
                        Session["UserRole"] = obj.EmployeeRole.EmpRole.ToString();
                        Session["UserName"] = obj.FirstName.ToString();
                        Session["EmpLoginError"] = "";
                        Session["PassLoginError"] = "";

                        ViewBag.UserName = Session["UserName"];

                        if (Session["UserRole"].Equals("Manager"))
                        {
                            return View("ManagerMenu");
                        }
                        else if (Session["UserRole"].Equals("Admin"))
                        {
                            return View("AdminView");
                        }
                        else if (Session["UserRole"].Equals("Employee"))
                        {
                            return View("EmployeeMenu");
                        }
                        
                    }
                    else
                    {
                        Models.Employee a = db.Employees.Find(e.EmployeeID);
                        if (a == null)
                        {
                            Session["EmpLoginError"] = "Invalid employee ID";
                            Session["PassLoginError"] = "";
                        }
                        else
                        {
                            Session["PassLoginError"] = "Invalid password";
                            Session["EmpLoginError"] = "";
                        }
                    }
                }
            }

            return View(e);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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;

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

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