예제 #1
0
        public ActionResult Settings(RoleSettingsViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    RoleSet roleSet = repository.RoleSets.FirstOrDefault(r => r.RoleSetId == model.RoleSetId);

                    RoleSetting[] roles = roleSet.Roles.ToArray();
                    RoleSetting[] roleSettings = model.Roles.ToArray();

                    for (int i = 0; i < roleSet.Roles.Count(); i++)
                    {
                        roles[i].IsActive = roleSettings[i].IsActive;
                    }

                    roleSet.Roles = roles.ToList();

                    repository.SaveRole(roleSet);

                    TempData["message"] = new Alert()
                    {
                        Class = "Success",
                        Title = "Role Settings Updated.",
                        Description = "Role settings for " + model.RoleSetName + " has been updated."
                    };

                    return RedirectToAction("Index");
                }
                catch (Exception e)
                {
                    TempData["message"] = new Alert(e);
                    return RedirectToAction("Index");
                }
            }
            else
            {
                return View();
            }
        }
예제 #2
0
        public ViewResult Settings(int id)
        {
            RoleSettingsViewModel model = new RoleSettingsViewModel();
            RoleSet roleSet = repository.RoleSets.FirstOrDefault(r => r.RoleSetId == id);

            model.RoleSetId = id;
            model.RoleSetName = roleSet.Name;
            model.Roles = roleSet.Roles.ToArray();

            return View(model);
        }