예제 #1
0
        public async Task <IActionResult> Add(RoleManagementViewModel model)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(model.NewDescription))
                {
                    model.NewDescription = string.Empty;
                }
                Role role = new Role {
                    Name = model.NewRoleName, Description = model.NewDescription
                };
                var addRoleResponse = await _authClient.AddRoleAsync <Role>(role);

                if (addRoleResponse.IsSuccessStatusCode)
                {
                    HttpContext.Session.SetString("SuccessMessage", "Role added successfully");
                    return(RedirectToAction("Index", "RoleManagement"));
                }
                else
                {
                    if (addRoleResponse.StatusCode == System.Net.HttpStatusCode.Conflict)
                    {
                        HttpContext.Session.SetString("ErrorMessage", addRoleResponse.BOSErrors[0].Message);
                        return(RedirectToAction("Index", "RoleManagement"));
                    }
                }
                return(RedirectToAction("Index", "Error"));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Index", "Error"));
            }
        }
예제 #2
0
        public async Task <IActionResult> Index()
        {
            try
            {
                var rolesResponse = await _authClient.GetRolesAsync <Role>();

                var model = new RoleManagementViewModel
                {
                    Roles          = rolesResponse.Roles,
                    NewRoleName    = null,
                    NewDescription = null
                };

                return(View(model));
            }
            catch (Exception)
            {
                throw new Exception("Error while fetching Roles");
            }
        }