Example #1
0
        protected string GetRealEmpNo()
        {
            //Set Environment Flat (This should move to a dedicate method/general method.)
            ViewBag.Environment  = ConfigurationManager.AppSettings["EnvironmentFlag"].ToString();
            ViewBag.ARIESAPI     = ConfigurationManager.AppSettings["ARIESRestServiceUrl"].ToString();
            ViewBag.IdentityLite = ConfigurationManager.AppSettings["PersonServiceUrl"].ToString();

            String User;
            Person person;

            User = "******";

            //Extract the username from the Identity.UserName
            //string contextuser = HttpContext.User.Identity.Name;
            //string[] splituser = AMPUtilities.SplitLoginName(contextuser);
            //User = splituser[1];

            try
            {
                person = _identityManager.GetPersonByUserName(User);
            }
            catch (Exception ex)
            {
                _errorEngine.LogError(ex, User);
                throw;
            }
            String EmpNo = person.EmpNo;

            return(EmpNo);
        }
        //[Route("~/")]


        public async Task <ActionResult> Index(string sortOrder, int?page, string searchString, string currentFilter)
        {
            try
            {
                String user;

                //Setup Code Logging
                DateTime From;
                DateTime To;
                String   MethodName  = "Dashboard/Index";
                String   Description = "Test Total Dashboard Index Code Performance";
                //Start Timing
                From = DateTime.Now;


                ViewBag.IDSortParm         = String.IsNullOrEmpty(sortOrder) ? "ID_desc" : "";
                ViewBag.ApprovedBudgetParm = sortOrder == "ApprovedBudget" ? "ApprovedBudget_desc" : "ApprovedBudget";
                ViewBag.StageParm          = sortOrder == "Stage" ? "Stage_desc" : "Stage";
                ViewBag.NextReviewParm     = sortOrder == "NextReview" ? "NextReview_desc" : "NextReview";

                //To match the route a string is being passed if sortOrder is empty
                if (String.IsNullOrEmpty(sortOrder))
                {
                    ViewBag.CurrentSort = "Firstload";
                }
                else
                {
                    ViewBag.CurrentSort = sortOrder;
                }

                //Get logon
                user = GetEmpNo();

                ViewBag.User = "******" + user;

                //Log user on page
                LogCall(user, "Dashboard/Index");

                if (searchString != null)
                {
                    page = 1;
                }
                else
                {
                    searchString = currentFilter;
                }

                ViewBag.CurrentFilter = searchString;

                // Control page size (10 fits the screen rather nice)
                //Page size max int value means there wont be any paging

                int pageSize = Session["isPagingEnabled"] == "F" ? int.MaxValue : 10;
                if (Session["isPagingEnabled"] == "F")
                {
                    ViewBag.PagingOn = "F";
                }

                //If first load or null then page 1 or actual value.
                int pageNumber = (page ?? 1);

                // Get all Project
                DashboardViewModel dashboardVM;
                try
                {
                    dashboardVM = await _ampServiceLayer.GetProjects(searchString, pageNumber, pageSize, user, sortOrder);
                }
                catch (Exception ex)
                {
                    errorengine.LogError(ex, "GetProjects - Dashboard/Index", user);
                    throw;
                }

                ViewBag.PageNumber  = pageNumber;
                ViewBag.PageSize    = pageSize;
                ViewBag.ProjectFrom = dashboardVM.userprojects.FirstItemOnPage;
                ViewBag.ProjectTo   = dashboardVM.userprojects.LastItemOnPage;

                // If this page loads for the first time, TempData will be empty, set it to NA as no save has happened yet.
                if (TempData["Success"] == null)
                {
                    TempData["Success"] = "NA"; ViewBag.Success = "NA";
                }

                //If TempData has been set to 1 meaning a succesfull save, set the ViewBag.Sucess status accordingly. This will be used by javascript on the edit view to show/hide save messages.
                if (TempData["Success"].ToString() == "1")
                {
                    ViewBag.Success = "1";
                }
                if (TempData["Success"].ToString() == "0")
                {
                    ViewBag.Success = "0";
                }

                TempData["VM"] = dashboardVM;

                ViewBag.DFIDTasksServer = ConfigurationManager.AppSettings["DFIDTasksUrl"].ToString();
                ViewBag.BaseUrl         = ConfigurationManager.AppSettings["BaseUrl"].ToString();
                ViewBag.ARIESUrl        = ConfigurationManager.AppSettings["ARIESUrl"].ToString();

                //End Timing and Record
                To = DateTime.Now;
                TimeSpan Result = To - From;
                _ampServiceLayer.InsertCodeLog(MethodName, Description, From, To, Result, user);

                //Return the view as a PagedList along with page number and size.
                return(View(dashboardVM));
            }
            catch (Exception ex)
            {
                errorengine.LogError(ex, "");
                throw;
            }
        }