Exemple #1
0
        /// <summary>
        /// Displays a list of all requests in the database.
        /// </summary>
        /// <returns>Returns a result based on status</returns>
        public ActionResult Index()
        {
            ActionResult     response;
            List <RequestPO> mappedRequests = new List <RequestPO>();

            //check for admin
            if (Session["RoleID"] != null && (int)Session["RoleID"] == 6)
            {
                //if user is an admin, access the database
                try
                {
                    //access database
                    List <RequestDO> allRequests = _RequestDataAccess.ViewRequests();

                    //map to presentation layer
                    foreach (RequestDO request in allRequests)
                    {
                        mappedRequests.Add(_RequestMapper.MapDOtoPO(request));
                    }

                    response = View(mappedRequests);
                }
                catch (Exception ex)
                {
                    //log error
                    _Logger.ErrorLog(MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ex);
                    response = RedirectToAction("Error", "Home");
                }
                finally { }
            }
            else
            {
                //if the user is not an admin, redirect to the login page
                response = RedirectToAction("Login", "Account");
            }

            return(response);
        }