/** * Returns the Manager View * * @return the ManagerViewData containing info needed for the view */ public IActionResult Index() { ViewData["Message"] = "Management page."; //Check if User is logged in, if not, make the url forbidden. This is useful if they attempt to type in the URL. if (HttpContext.Session.GetInt32(SessionKeyRoleId) == null) { return(StatusCode(403)); } //Check if they are a Manager, if not, send them to the forbidden page. int Roleid = (int)HttpContext.Session.GetInt32(SessionKeyRoleId); if (Roleid != 2) { return(StatusCode(403)); } // Creates the ManagerViewData to be passed back to the Manager view UserContext context = HttpContext.RequestServices.GetService(typeof(UserContext)) as UserContext; ManagerViewData data = new ManagerViewData(); User user = context.retrieveUserDetails((int)HttpContext.Session.GetInt32(SessionKeyId)); data.Employees = context.GetEmployeesForManager(user.ID); data.CurrentUser = user; PendingRequestsContext pcontext = HttpContext.RequestServices.GetService(typeof(PendingRequestsContext)) as PendingRequestsContext; data.PendingRequests = pcontext.GetAllPendingRequestsManager(user.ID); return(View(data)); }
/** * Returns the Employee view * * @return the AdminViewData */ public IActionResult Index() { ViewData["Message"] = "Employee page."; //Check if User is logged in, if not, make the url forbidden. This is useful if they attempt to type in the URL. if (HttpContext.Session.GetInt32(SessionKeyRoleId) == null) { return(StatusCode(403)); } //Check if they are a Manager or an Employee, if not, send them to the forbidden page. int Roleid = (int)HttpContext.Session.GetInt32(SessionKeyRoleId); if ((Roleid != 1) && (Roleid != 2)) { return(StatusCode(403)); } dynamic mymodel = new ExpandoObject(); // set user and transaction contexts TransactionContext transactionContext = HttpContext.RequestServices.GetService(typeof(TransactionContext)) as TransactionContext; UserContext userContext = HttpContext.RequestServices.GetService(typeof(UserContext)) as UserContext; // gets the current user's details User user = userContext.retrieveUserDetails((int)HttpContext.Session.GetInt32(SessionKeyId)); mymodel.CurrentUser = user; // get and set the UI's budget double budget = transactionContext.getCurrentBudget(user.ID, user.ChangeAnnualBudgetDate, user.StartBudget, user.AnnualBudget, user.ChangeAnnualBudget); mymodel.Budget = budget; //get the user's max budget spend so they can't spend more than they currently have and will //accrue for the year var futureAccruedBudget = getUserMaxBudgetRequest(user); var maxBudget = futureAccruedBudget + budget; if (maxBudget > user.AnnualBudget) { maxBudget = user.AnnualBudget; } mymodel.MaxBudgetRequest = maxBudget; // pending request PendingRequestsContext context = HttpContext.RequestServices.GetService(typeof(PendingRequestsContext)) as PendingRequestsContext; mymodel.PendingRequests = context.GetAllPendingRequests(user.ID); // past requests mymodel.PastRequests = transactionContext.GetAllPastRequests((int)HttpContext.Session.GetInt32(SessionKeyId)); return(View(mymodel)); }
/** * Function called when a manager declines a request * * @param ID id of the Request being declined * @return id of the Request being declined */ public IActionResult DeclineRequest(string ID) { ViewData["Message"] = "Management page."; // gets employee's pending requests PendingRequestsContext Pendingcontext = HttpContext.RequestServices.GetService(typeof(PendingRequestsContext)) as PendingRequestsContext; var ApprovedRequest = Pendingcontext.DeclinePendingRequest(ID); // Returns the ID that was passed in return(Json(new { id = ID }));; }
/** * This function gets information about a selected user to be displayed on the right hand side of the manager screen * * @param UserID ID of the user being selected * @return the selected users information */ public IActionResult GetSelectedInfo(int UserID) { ViewData["Message"] = "Management page."; // gets selected employee UserContext context = HttpContext.RequestServices.GetService(typeof(UserContext)) as UserContext; User selectedEmployee = context.retrieveUserDetails(UserID); // gets employee's pending requests PendingRequestsContext Pendingcontext = HttpContext.RequestServices.GetService(typeof(PendingRequestsContext)) as PendingRequestsContext; var pendingRequests = Pendingcontext.GetAllPendingRequests(UserID); // gets employee's past requests TransactionContext transactionContext = HttpContext.RequestServices.GetService(typeof(TransactionContext)) as TransactionContext; var pastRequests = transactionContext.GetAllPastRequests(UserID); // gets the employees current budget double budget = transactionContext.getCurrentBudget(selectedEmployee.ID, selectedEmployee.ChangeAnnualBudgetDate, selectedEmployee.StartBudget, selectedEmployee.AnnualBudget, selectedEmployee.ChangeAnnualBudget); // Returns info of the employee that was selected back to the view return(Json(new { id = UserID, selectedEmployee = selectedEmployee, currentBudget = budget, pendingRequests = pendingRequests, pastRequests = pastRequests })); }
public IActionResult SubmitRequest() { // Build user model PendingRequest newRequest = new PendingRequest(); newRequest.Description = HttpContext.Request.Form["description"].ToString(); newRequest.Cost = HttpContext.Request.Form["requestCost"].ToString(); DateTime dateTimeNow = DateTime.Now; newRequest.Date = dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss"); // Get context PendingRequestsContext pendingRequestContext = HttpContext.RequestServices.GetService(typeof(TevenStudiosBudgetTracker.Models.PendingRequestsContext)) as PendingRequestsContext; //Save user to database, get result int result = pendingRequestContext.SubmitPendingRequest(newRequest, (int)HttpContext.Session.GetInt32(SessionKeyId)); if (result > 0) { ViewBag.Result = " Request was successfully submitted"; ViewBag.isSuccess = true; } else { ViewBag.Result = "Something went wrong"; ViewBag.isSuccess = false; } ViewData["Message"] = "Employee page."; dynamic mymodel = new ExpandoObject(); // set user and transaction contexts TransactionContext transactionContext = HttpContext.RequestServices.GetService(typeof(TransactionContext)) as TransactionContext; UserContext userContext = HttpContext.RequestServices.GetService(typeof(UserContext)) as UserContext; // gets the current user's details User user = userContext.retrieveUserDetails((int)HttpContext.Session.GetInt32(SessionKeyId)); mymodel.CurrentUser = user; // get and set the UI's budget double budget = transactionContext.getCurrentBudget(user.ID, user.ChangeAnnualBudgetDate, user.StartBudget, user.AnnualBudget, user.ChangeAnnualBudget); mymodel.Budget = budget; //get the user's max budget spend so they can't spend more than they currently have and will //accrue for the year var futureAccruedBudget = getUserMaxBudgetRequest(user); var maxBudget = futureAccruedBudget + budget; if (maxBudget > user.AnnualBudget) { maxBudget = user.AnnualBudget; } mymodel.MaxBudgetRequest = maxBudget; // pending request PendingRequestsContext context = HttpContext.RequestServices.GetService(typeof(PendingRequestsContext)) as PendingRequestsContext; mymodel.PendingRequests = context.GetAllPendingRequests(user.ID); // past requests mymodel.PastRequests = transactionContext.GetAllPastRequests((int)HttpContext.Session.GetInt32(SessionKeyId)); return(View("Index", mymodel)); }