/// <summary> /// 用户更新用户名 /// </summary> /// <param name="session"></param> /// <param name="user"></param> /// <param name="newName"></param> /// <param name="currentAccountNo"></param> /// <returns></returns> public static bool UpdateName(Session session, User user, string newName, string currentAccountNo) { if (string.IsNullOrEmpty(newName)) throw new ArgumentNullException("newName"); if (newName.Equals(user.Name)) return true; var account = session.Load<Account>(m => m.Name.Equals(user.Name)); if(account == null) throw new ArgumentException(string.Format("用户{0}不存在", user.Name), "user"); account.Name = newName; user.Name = newName; return session.Update(user) && session.Update(account) && user.Deactive(session, currentAccountNo); }
public User GetProfile() { if (User == null) { Criteria<User> q = new Criteria<User>().Where(m => m.Name.Equals(Name)); User = q.Load(); } return User; }
/// <summary> /// 增加用户 /// </summary> /// <param name="session">数据库会话</param> /// <param name="user">用户</param> /// <param name="currentAccountNo">当前操作者</param> /// <returns>是否操作成功</returns> public static bool AddUser(Session session, User user, string currentAccountNo) { return session.Create(user) && user.AddNotExistAccount(session, currentAccountNo); }
public ActionResult Create(FormCollection collection) { var model = new User(); TryUpdateModel(model, collection.ToValueProvider()); if (!ModelState.IsValid) { return View(model); } if (model.Name.Equals("root", StringComparison.CurrentCultureIgnoreCase)) { ModelState.AddModelError("Name", "该名称已被使用"); return View(model); } using (var session = new SessionFactory().OpenSession()) { session.BeginTransaction(); if (Exist<User>(session, m => m.Code.Equals(model.Code) || m.Code.Equals(model.Name) || m.Name.Equals(model.Code) || m.Name.Equals(model.Name))) { FlashWarn("用户 {0} 工号或者用户名已经存在,创建失败。", model.Name); return View(model); } model.IsActive = false; model.CreatedAt = DateTime.Now; model.CreatedBy = CurrentAccountNo; ViewData.Model = model; if (UserService.AddUser(session, model, CurrentAccountNo)) { session.Commit(); UserActivity.UserNameIdMapHolder.Reset(); FlashSuccess("创建用户[{0}]成功!", model.Name); return Close(); } session.Rollback(); FlashFailure("创建用户[{0}]失败!", model.Name); return View(); } }