コード例 #1
0
        public SaveResult Lock(UserIdRequest request)
        {
            try
            {
                // TODO: js error display

                if (request.Id == 0)
                {
                    return new SaveResult {
                               Status = "error", Message = "Id is not valid!"
                    }
                }
                ;

                if (UserManager.IsInRole(request.Id, "Admin"))
                {
                    return new SaveResult {
                               Status = "error", Message = "User is admin!"
                    }
                }
                ;

                RepositoryAspNetUsers repo = new RepositoryAspNetUsers();

                AspNetUser user = repo.GetById(request.Id);

                user.LockoutEnabled = true;

                user.LockoutEndDateUtc = new DateTime(2100, 1, 1);

                repo.Update(user);

                return(new SaveResult {
                    Status = "success"
                });
            }
            catch (Exception ex)
            {
                return(new SaveResult {
                    Status = "error", Message = ex.Message
                });
            }
        }
コード例 #2
0
        public virtual SaveResult SetEmail(SetEmailViewModel request)
        {
            try
            {
                if (request.UserId == 0)
                {
                    return new SaveResult {
                               Status = "error", Message = "Id is not valid!"
                    }
                }
                ;

                if (UserManager.IsInRole(request.UserId, "Admin"))
                {
                    return new SaveResult {
                               Status = "error", Message = "User is admin!"
                    }
                }
                ;

                RepositoryAspNetUsers repo = new RepositoryAspNetUsers();

                AspNetUser user = repo.GetById(request.UserId);

                user.Email = request.NewEmail;

                repo.Update(user);

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