예제 #1
0
        public JsonResult RolesCreate(ViewModels.RoleViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { Result = "ERROR", Message = BaseResource.Get("InvalidData") }));
            }

            try
            {
                var rcreateres = _roleManager.Create(new IdentityRole()
                {
                    Name = model.Name
                });
                if (rcreateres.Succeeded)
                {
                    var newrole = _roleManager.FindByName(model.Name);
                    return(Json(new { Result = "OK", Record = new ViewModels.RoleViewModel()
                                      {
                                          Id = newrole.Id, Name = newrole.Name
                                      } }));
                }
                else
                {
                    return(Json(new { Result = "ERROR", Message = rcreateres.Errors.First().ToString() }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
예제 #2
0
        public JsonResult RolesUpdate(ViewModels.RoleViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { Result = "ERROR", Message = BaseResource.Get("InvalidData") }));
            }

            try
            {
                var role = _roleManager.FindById(model.Id);
                role.Name = model.Name;
                _roleManager.Update(role);

                return(Json(new { Result = "OK", Message = "data saved.." }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }