コード例 #1
0
 public ActionResult AddNewRole(ManagementViewModel model) {
     if (!ModelState.IsValid) {
         ModelState.AddModelError("", "Model validation Error");
         return RedirectToAction("Index", "Management");
     }
     UserRoleManagerResult addNewRole = UserRoleManager.AddRole(model.NewRole);
     if (addNewRole.Success) {
         TempData["RoleAdded"] = "Roled Added";
     }
     else {
         TempData["RoleAdded"] = addNewRole.ErrorMessage;
         return RedirectToAction("Index", "Management");
     }
     return RedirectToAction("Index", "Management");
 }
コード例 #2
0
 public ActionResult RemoveBranch(ManagementViewModel model) {
     if (!ModelState.IsValid) {
         ModelState.AddModelError("", "Model validation Error");
         return RedirectToAction("Index", "Management");
     }
     BranchManagerResult removeBranch = BranchManager.RemoveBranch(model.BranchToRemove);
     if (removeBranch.Success) {
         TempData["BranchAdded"] = "Branch Removed";
     }
     else {
         TempData["RoleAdded"] = removeBranch.ErrorMessage;
         return RedirectToAction("Index", "Management");
     }
     return RedirectToAction("Index", "Management");
 }
コード例 #3
0
 public ActionResult AdddNewBranch(ManagementViewModel model) {
     if (!ModelState.IsValid) {
         ModelState.AddModelError("", "Model validation Error");
         return RedirectToAction("Index", "Management");
     }
     BranchManagerResult addNewBranch = BranchManager.AddBranch(model.NewBranch);
     if (addNewBranch.Success) {
         TempData["BranchAdded"] = "Branch Added";
     }
     else {
         TempData["RoleAdded"] = addNewBranch.ErrorMessage;
         return RedirectToAction("Index", "Management");
     }
     return RedirectToAction("Index", "Management");
 }
コード例 #4
0
        public ActionResult Index(ManagementViewModel model, int? page) {
            // Error Filtering
            if (TempData["RoleAdded"] != null) {
                ModelState.AddModelError(string.Empty, TempData["RoleAdded"].ToString());
            }
            if (TempData["BranchAdded"] != null) {
                ModelState.AddModelError(string.Empty, TempData["BranchAdded"].ToString());
            }
            if (TempData["RoleRemoved"] != null) {
                ModelState.AddModelError(string.Empty, TempData["RoleRemoved"].ToString());
            }
            if (TempData["UserRemoved"] != null) {
                ModelState.AddModelError(string.Empty, TempData["UserRemoved"].ToString());
            }
            if (TempData["ManagementError"] != null) {
                ModelState.AddModelError(string.Empty, TempData["ManagementError"].ToString());
            }
            if (TempData["UserUpdated"] != null) {
                ModelState.AddModelError(string.Empty, TempData["UserUpdated"].ToString());
            }
            if (TempData["EditRole"] != null) {
                ModelState.AddModelError(string.Empty, TempData["EditRole"].ToString());
            }
            if (TempData["ViewAllOrders"] != null) {
                ModelState.AddModelError(string.Empty, TempData["ViewAllOrders"].ToString());
            }

            // Roels for DropDown
            UserRoleManagerResult getRolesResult = UserRoleManager.GetRoles();
            if (getRolesResult.Success) {
                model.RoleList = getRolesResult.Roles.Select(x => new SelectListItem {Text = x, Value = x}).ToList();
            }
            else {
                TempData["ManagementError"] = getRolesResult.ErrorMessage;
                ModelState.AddModelError(string.Empty, TempData["ManagementError"].ToString());
            }

            // branches for DropDown
            BranchManagerResult getBranchesResult = BranchManager.GetBranchesNames();
            if (getBranchesResult.Success) {
                model.BracnhList = getBranchesResult.BranchesNames.Select(x => new SelectListItem {Text = x, Value = x}).ToList();
            }
            else {
                TempData["ManagementError"] = getBranchesResult.ErrorMessage;
            }

            // Uset List
            UserManagerResult getUserListResult = UserManager.GetUsers();
            if (getUserListResult.Success) {
                model.UserList = getUserListResult.UserList.ToList();
                foreach (Account account in getUserListResult.UserList) {
                    UserRoleManagerResult getUserRoles = UserRoleManager.GetUserRoles(account.Email.Replace(" ", String.Empty));
                    string roles = null;
                    // remove this IF when ROLES fully implanted
                    if (getUserRoles != null) {
                        roles = getUserRoles.Roles.Aggregate(roles, (current, role) => current + role + " ");
                    }
                    ManagementAccountDisplayModelView accountModel = new ManagementAccountDisplayModelView {
                        Email = account.Email.Replace(" ", String.Empty),
                        LastName = account.LastName.Replace(" ", String.Empty),
                        FirstName = account.FirstName.Replace(" ", String.Empty),
                        Gender = account.Gender.Replace(" ", String.Empty),
                        BirthDate = account.BirthDate.Replace(" ", String.Empty),
                        PhoneNumber = account.PhoneNumber,
                        Roles = roles
                    };
                    model.AccountModels.Add(accountModel);
                }
            }
            else {
                TempData["ManagementError"] = getUserListResult.ErrorMessage;
            }

            return View(model);
        }
コード例 #5
0
 public ActionResult RemvoeRole(ManagementViewModel model) {
     if (!ModelState.IsValid) {
         ModelState.AddModelError("", "Model validation Error");
         return RedirectToAction("Index", "Management");
     }
     UserRoleManagerResult removeRole = UserRoleManager.RemoveRole(model.RoleToRemove);
     if (removeRole.Success) {
         TempData["RoleRemoved"] = "Role Removed";
     }
     else {
         TempData["RoleRemoved"] = removeRole.ErrorMessage;
         return RedirectToAction("Index", "Management");
     }
     return RedirectToAction("Index", "Management");
 }