コード例 #1
0
        // GET: Employees/ChooseDirectReports/5
        // Sends the form to enable a manager to select their direct reports
        public ActionResult ChooseDirectReports(int?id)
        {
            // Determine whether we can continue, non-null id
            if (id == null)
            {
                return(RedirectToAction("index"));
            }
            else
            {
                // Verify that the security context user has the 'Manager' role claim
                // e.g. (User as ClaimsPrincipal).HasClaim(ClaimTypes.Role, "Manager")

                var fetchedObject = m.GetEmployeeByIdWithAssociatedData(id.Value);
                var username      = fetchedObject.IdentityUserId;

                if (m.IsUserAManager(username))
                {
                    // Prepare and configure a form to send to the view
                    // Present the view
                    var chooseEmp = new EmployeeDirectReportsForm();
                    chooseEmp.Id        = id.Value;
                    chooseEmp.Employees = new MultiSelectList(m.GetAllEmployeesNoManager(), "Id", "FullName");

                    return(View(chooseEmp));
                }
                else
                {
                    // User is not a manager
                    return(RedirectToAction("Details", new { id = id }));
                }
            }
        }
コード例 #2
0
        // GET: Employees/ChooseDirectReports/5
        // Sends the form to enable a manager to select their direct reports
        public ActionResult ChooseDirectReports(int? id)
        {
            // Determine whether we can continue, non-null id
            if (id == null)
            {
                throw new NotImplementedException();
            }
            //else if(User.IsInRole("Manager"))
            else if ((User as ClaimsPrincipal).HasClaim(ClaimTypes.Role, "Manager") == true)
            {
                // Verify that the security context user has the 'Manager' role claim
                // e.g. (User as ClaimsPrincipal).HasClaim(ClaimTypes.Role, "Manager")
                // Prepare and configure a form to send to the view
                // Present the view
                var form = new EmployeeDirectReportsForm();
                form.Id = (int)id;
                form.Employees = new SelectList(m.GetAllEmployeesNoManager(), "Id", "FullName");

                return View(form);
            }

            //Error
            throw new NotImplementedException();


        }