public ActionResult Index(string category)
        {
            MyRequestsViewModel theVM = new MyRequestsViewModel();
            Status theStatus;

            try {
                theVM.TheCategory = (Category)Enum.Parse(typeof(Category), category);
                switch (theVM.TheCategory)
                {
                case Category.Drafts:
                    theStatus = Status.New;
                    break;

                case Category.Pending:
                    theStatus = Status.Executing;
                    break;

                case Category.Completed:
                    theStatus = Status.Fulfilled;
                    break;

                default:
                    throw new Exception();
                }

                theVM.TheSearchRequests = TheSReqController.GetFESearchRequests(User.Identity.GetUserId(), theStatus);
            } catch {
                theVM.TheCategory       = Category.All;
                theVM.TheSearchRequests = TheSReqController.GetFESearchRequests(User.Identity.GetUserId());
            }
            theVM.TheSearchRequests.OrderByDescending(sReq => sReq.TheLatestExecution.StartedOn);
            theVM.TheBannerMsg = (MR_BannerMsg)LoadBannerMsg();

            return(View(theVM));
        }
Пример #2
0
        public ActionResult MyRequests()
        {
            // Get the logged in Site ID from the session
            int?SiteID = Session["SiteID"] as int?;

            // if there is none, redirect to the login page
            if (!SiteID.HasValue)
            {
                return(RedirectToAction("Login", "Account"));
            }

            MyRequestsViewModel vm = new MyRequestsViewModel
            {
                SiteID = SiteID.Value
            };

            // get all requests for the current user
            string sql = String.Format("SELECT r.RequestID, i.ItemName, i.Category1, i.Category2, i.StorageType, r.RequestedQuantity, r.Status, r.FulfilledQuantity, i.ItemID " +
                                       "FROM request r " +
                                       "INNER JOIN item i on i.ItemID = r.ItemID " +
                                       "WHERE r.Username = '******' " +
                                       "ORDER BY r.RequestID DESC ;", Session["Username"].ToString());

            vm.Requests = GetRequests(sql);

            // update the Closed property to a more informative value based on the fulfilled / requested quantities
            foreach (Request r in vm.Requests)
            {
                if (r.Status.Equals("Closed"))
                {
                    if (r.FulfilledQuantity.Equals(r.RequestedQuantity))
                    {
                        r.Status = "Complete";
                    }
                    else if (r.FulfilledQuantity > 0)
                    {
                        r.Status = "Partially Fulfilled";
                    }
                    else
                    {
                        r.Status = "Rejected";
                    }
                }
            }

            return(View(vm));
        }