Ejemplo n.º 1
0
        public SaveResult Update(RoleViewModel model)
        {
            try
            {
                ApplicationRole role = RoleManager.FindById(model.Id);

                role.Name = model.Name;

                var result = RoleManager.Update(role);

                if (!result.Succeeded)
                {
                    return new SaveResult {
                               Status = "error", Message = result.Errors.First()
                    }
                }
                ;

                RolesSingleton.ClearInstance();

                return(new SaveResult {
                    Status = "success"
                });
            }
            catch (Exception ex)
            {
                return(new SaveResult {
                    Status = "error", Message = ex.Message
                });
            }
        }
Ejemplo n.º 2
0
        public SaveResult Delete(RoleViewModel model)
        {
            try
            {
                if (model.Id == 0)
                {
                    return new SaveResult {
                               Status = "error", Message = "No records for deletion!"
                    }
                }
                ;

                ApplicationRole role = RoleManager.FindById(model.Id);

                if (role == null)
                {
                    return new SaveResult {
                               Status = "error", Message = "Can't find role by id!"
                    }
                }
                ;

                IdentityResult result = RoleManager.Delete(role);

                if (!result.Succeeded)
                {
                    return new SaveResult {
                               Status = "error", Message = result.Errors.First()
                    }
                }
                ;

                RolesSingleton.ClearInstance();

                return(new SaveResult {
                    Status = "success"
                });
            }
            catch (Exception ex)
            {
                return(new SaveResult {
                    Status = "error", Message = ex.Message
                });
            }
        }