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); } }
/// <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; }
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(); }
public void UpdateUser(User user) { _userRepository.Update(user); if (_sessionManager.User.UserId == user.UserId) { _sessionManager.User = user; } }
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", "对不起,您没有权限进行操作。"); } }