示例#1
0
        public void Register(User user)
        {
            if (!_roleService.RegisterPower())
            {
                throw new DomainException("Error", "本站已经关闭注册功能。");
            }
            else if (_userRepository.CheckUserNameExist(user.UserName))
            {
                throw new DomainException("UserName", "该用户名已经被注册。");
            }
            else if (_userRepository.CheckEmailExist(user.Email))
            {
                throw new DomainException("Email", "该邮箱已经被注册。");
            }
            else
            {
                user.NiceName = user.UserName;

                user.RegisterDate = DateTime.Now;

                user.Status = UserStatus.Normal;

                user.Role = int.Parse(_settingService.GetSetting("DefaultRole"));

                _userRepository.Add(user);
            }
        }
示例#2
0
 /// <summary>
 /// 取得用户的头像
 /// </summary>
 /// <param name="Html"></param>
 /// <param name="Url"></param>
 /// <param name="user"></param>
 /// <returns></returns>
 public static string Picture(this HtmlHelper Html, UrlHelper Url, User user)
 {
     string picture = Url.Content("~/Content/Include/images/picture.png");
     if (user != null && user.Extends.ContainsKey("Picture"))
     {
         picture = user.Extends["Picture"];
     }
     return picture;
 }
示例#3
0
        public ActionResult Add(UserAddModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    User user = new User() { UserName = model.UserName, Email = model.Email, Role = model.Role, RegisterDate = DateTime.Now, NiceName = model.UserName };
                    _userService.AddUser(user);
                    return RedirectToAction("Index", new { Message = "用户添加成功。" });
                }
                catch (Exception ex)
                {
                    ViewBag.Message = ex.Message;
                }
            }
            else
            {

                foreach (var value in ModelState.Values)
                {
                    foreach (var error in value.Errors)
                    {
                        ViewBag.Message = error.ErrorMessage;
                        break;
                    }
                    if (ViewBag.Message != null)
                    {
                        break;
                    }
                }
            }
            return View();
        }
示例#4
0
 public void UpdateUser(User user)
 {
     _userRepository.Update(user);
     if (_sessionManager.User.UserId == user.UserId)
     {
         _sessionManager.User = user;
     }
 }
示例#5
0
 public void AddUser(User user)
 {
     if (_roleService.AdminPower())
     {
         if (_userRepository.CheckUserNameExist(user.UserName))
         {
             throw new DomainException("UserName", "该用户名已经被注册。");
         }
         else if (_userRepository.CheckEmailExist(user.Email))
         {
             throw new DomainException("Email", "该邮箱已经被注册。");
         }
         _userRepository.Add(user);
     }
     else
     {
         throw new DomainException("NoPower", "对不起,您没有权限进行操作。");
     }
 }