public void AddUser(EUser user) { using (var dmTrans = _rep.GetTransaction()) { try { var tran = dmTrans.BeginTransaction(); if (_rep.Get<EUser>(p => p.UserName == user.UserName) != null) { throw new ArgumentException("存在相同用户名!"); }; user.UserAvatar = "/Content/Images/noPic.jpg"; user.Password = user.Password.GetMD5By32(); user.LastLoginTime = DateTime.Now; //添加用户 _rep.Add(user, tran); dmTrans.Commit(); } catch { dmTrans.Rollback(); throw; } } }
private EUser RegisterMemberByOpenLogin(EUser user, int? deviceGpsTypeId, string deviceGpsNo, string deviceGpsSimNo, int? roleId) { using (var dmTrans = _rep.GetTransaction()) { try { var tran = dmTrans.BeginTransaction(); //添加用户 _rep.Add(user, tran); if (roleId.HasValue) { //添加角色 _rep.Add(new EUserRole() { UserId = user.Id, RoleId = roleId.Value }, null, tran); } //添加车辆分组 var deviceGroup = new EDeviceGroup() { DeviceGroupName = "默认分组", DeviceGroupOrderId = 0, IsRoot = true, UserId = user.Id }; _rep.Add(deviceGroup, tran); if (deviceGpsNo.HasValue() && deviceGpsSimNo.HasValue()) { //添加设备 if (_deviceService.CheckDeviceGpsNoIsExist(deviceGpsNo)) { throw new BusinessException("已经存在Gps设备号!"); } if (_deviceService.CheckDeviceGpsSimNoIsExist(deviceGpsSimNo)) { throw new BusinessException("已经存在Sim卡号!"); } var device = new EDevice { UserId = user.Id, DeviceName = deviceGpsNo, DeviceGpsNo = deviceGpsNo, DeviceGpsSimNo = deviceGpsSimNo, DeviceGpsTypeId = deviceGpsTypeId, DeviceTypeId = 1, DeviceGroupId = deviceGroup.Id, CreateTime = DateTime.Now, NodeId = _nodeService.GetNodeIdByCreateTime(DateTime.Now), DeviceGpsInstallTime = DateTime.Now, DeviceExpireTime = DateTime.Now.AddYears(1) }; device.DeviceGpsCode = _deviceService.GetDeviceGpsCode(device.DeviceGpsTypeId.Value, device.DeviceGpsNo, device.DeviceGpsSimNo); _rep.Add(device, tran); _rep.Add(new EAlarmSettingOverspeed() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingInOutArea() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingParkingNotStalled() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingTired() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingAutoFortify() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59), Radius = 50, ActivationTime = 10 }, tran); _rep.Add(new EAlarmSettingMainPowerBreak() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); } dmTrans.Commit(); //更新车辆分组缓存 _cacheService.RemoveByKey(Cdev.Core.Gps.CacheKey.Gps_DeviceGroups_All); return user; } catch { dmTrans.Rollback(); throw; } } }
public void RegisterMember(string userName, int? deviceGpsTypeId, string deviceGpsNo, string deviceGpsSimNo, string password, int? roleId) { using (var dmTrans = _rep.GetTransaction()) { try { var tran = dmTrans.BeginTransaction(); var user = new EUser() { UserName = userName, NickName = userName, Password = password.GetMD5By32(), UserAvatar = "/Content/Images/noPic.jpg", LastLoginTime = DateTime.Now }; if (_rep.Get<EUser>(p => p.UserName == user.UserName) != null) { throw new ArgumentException("存在相同用户名!"); }; //添加用户 _rep.Add(user, tran); if (roleId.HasValue) { //添加角色 _rep.Add(new EUserRole() { UserId = user.Id, RoleId = roleId.Value }, null, tran); } //添加车辆分组 var deviceGroup = new EDeviceGroup() { DeviceGroupName = "默认分组", DeviceGroupOrderId = 0, IsRoot = true, UserId = user.Id }; _rep.Add(deviceGroup, tran); if (deviceGpsNo.HasValue() && deviceGpsSimNo.HasValue()) { //添加设备 if (_deviceService.CheckDeviceGpsNoIsExist(deviceGpsNo)) { throw new BusinessException("已经存在Gps设备号!"); } if (_deviceService.CheckDeviceGpsSimNoIsExist(deviceGpsSimNo)) { throw new BusinessException("已经存在Sim卡号!"); } var device = new EDevice { UserId = user.Id, DeviceName = deviceGpsNo, DeviceGpsNo = deviceGpsNo, DeviceGpsSimNo = deviceGpsSimNo, DeviceGpsTypeId = deviceGpsTypeId, DeviceTypeId = 1, DeviceGroupId = deviceGroup.Id, CreateTime = DateTime.Now, NodeId = _nodeService.GetNodeIdByCreateTime(DateTime.Now), DeviceGpsInstallTime = DateTime.Now, DeviceExpireTime = DateTime.Now.AddYears(5) }; device.DeviceGpsCode = _deviceService.GetDeviceGpsCode(device.DeviceGpsTypeId.Value, device.DeviceGpsNo, device.DeviceGpsSimNo); _rep.Add(device, tran); _rep.Add(new EAlarmSettingOverspeed() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingInOutArea() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingParkingNotStalled() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingTired() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); _rep.Add(new EAlarmSettingAutoFortify() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59), Radius = 50, ActivationTime = 10 }, tran); _rep.Add(new EAlarmSettingMainPowerBreak() { DeviceId = device.Id, ReceiveStartTime = new TimeSpan(0, 0, 0), ReceiveEndTime = new TimeSpan(23, 59, 59) }, tran); } dmTrans.Commit(); //更新车辆分组缓存 _cacheService.RemoveByKey(Cdev.Core.Gps.CacheKey.Gps_DeviceGroups_All); } catch { dmTrans.Rollback(); throw; } } }
/// <summary> /// 编辑 /// </summary> /// <returns></returns> public ActionResult EditMember(EUser user) { if (user.Id == 0) { CheckIsHaveMBPermission(47); _aUserService.AddMember(user, null, 1);//自动分配一个普通会员 return JsonResult(user, "添加成功!"); } else { CheckIsHaveMBPermission(48); _userService.SaveMember(user); return JsonResult(user, "保存成功!"); } }
/// <summary> /// 编辑 /// </summary> /// <returns></returns> public ActionResult EditUser(EUser user) { if (user.Id == 0) { CheckIsHaveMBPermission(77); _aUserService.AddUser(user); return JsonResult(user, "添加成功!"); } else { CheckIsHaveMBPermission(78); _userService.SaveUser(user); return JsonResult(user, "保存成功!"); } }
private EPassport LoginByAppOpenId(EUser user) { if (user == null) { throw new NullReferenceException("不存在用户!"); } if (user.UserStatus == EnumUserStatus.Forbid) { throw new NullReferenceException("当前用户已经被禁止登录!"); } user.AppTicket = Guid.NewGuid().ToString(); _rep.Save(user, p => p.Id == user.Id, p => new Columns(p.AppTicket)); return new EPassport() { User = user }; }
private void LoginByOpenLogin(EUser user) { if (user == null) { throw new NullReferenceException("不存在用户!"); } if (user.UserStatus == EnumUserStatus.Forbid) { throw new NullReferenceException("当前用户已经被禁止登录!"); } var passport = new EPassport(); passport.User = user; passport.Roles = _userService.GetVUserRolesByUserId(user.Id); if (user.IsSuperAdmin) { passport.Menu = _menuService.GetMenuTree(); } else { passport.Auths = _menuService.GetAllMenuAuthsByUserId(user.Id); passport.Menu = _menuService.GetMenuTreeByUserId(user.Id, passport.Auths); } //更新用户信息 _rep.Save(new EUser() { LastLoginTime = DateTime.Now }, p => p.Id == user.Id, p => new Columns(p.LastLoginTime)); _stateService.SavePassport(passport); }
public void AddMember(EUser user, int? parentUserId, int? roleId) { using (var dmTrans = _rep.GetTransaction()) { try { var tran = dmTrans.BeginTransaction(); if (_rep.Get<EUser>(p => p.UserName == user.UserName) != null) { throw new ArgumentException("存在相同用户名!"); }; user.UserAvatar = "/Content/Images/noPic.jpg"; user.Password = user.Password.GetMD5By32(); user.LastLoginTime = DateTime.Now; user.ParentUserId = parentUserId; //添加用户 _rep.Add(user, tran); if (roleId.HasValue) { //添加角色 _rep.Add(new EUserRole() { UserId = user.Id, RoleId = roleId.Value }, null, tran); } dmTrans.Commit(); } catch { dmTrans.Rollback(); throw; } } }
/// <summary> /// 保存 /// </summary> public void SaveMember(EUser user) { _rep.Save(user, p => p.Id == user.Id, p => new Columns( p.Address, p.Email, p.Fax, p.NickName, p.Mobile, p.QQ, p.Sex, p.UserStatus)); }
/// <summary> /// 保存 /// </summary> public void SaveUser(EUser user) { _rep.Save(user, p => p.Id == user.Id, p => new Columns( p.Address, p.Email, p.Fax, p.NickName, p.Mobile, p.QQ, p.Sex, p.UserStatus, p.ParentUserId, p.IsAdmin, p.IsSuperAdmin)); }
/// <summary> /// 保存用户基本信息 /// </summary> public EUser EditMyProfile(EUser user) { _rep.Save(user, p => p.Id == user.Id, p => new Columns( p.Address, p.Email, p.Fax, p.NickName, p.Mobile, p.QQ, p.Sex, p.UserAvatar)); _cacheService.UpdateCacheDependent(CacheKey.Core_Auto_Complete_User); return _rep.Get<EUser>(p => p.Id == user.Id); }
/// <summary> /// 保存用户基本信息 /// </summary> /// <returns></returns> public ActionResult EditMyProfile(EUser user) { _userService.EditMyProfile(user); return JsonResult(user, "保存成功!"); }
public void RegisterMember(string userName, int deviceGpsTypeId, string deviceGpsNo, string deviceGpsSimNo, string password, int? roleId) { using (var dmTrans = _rep.GetTransaction()) { try { var tran = dmTrans.BeginTransaction(); var user = new EUser() { UserName = userName, NickName = userName, Password = password.GetMD5By32(), UserAvatar = "/Content/Images/noPic.jpg", LastLoginTime = DateTime.Now }; if (_rep.Get<EUser>(p => p.UserName == user.UserName) != null) { throw new ArgumentException("存在相同用户名!"); }; if (roleId.HasValue) { //添加角色 _rep.Add(new EUserRole() { UserId = user.Id, RoleId = roleId.Value }, null, tran); } //添加用户 _rep.Add(user, tran); dmTrans.Commit(); } catch { dmTrans.Rollback(); throw; } } }
public EUser RegisterMemberByQQLogin(string openId, string accessToken, int expiresIn, string userAvatar, string nickName, EnumSex sex, int? deviceGpsTypeId, string deviceGpsNo, string deviceGpsSimNo, int? roleId) { var user = new EUser() { QQOpenId = openId, QQAccessToken = accessToken, QQExpiresIn = expiresIn, Sex = sex, IsCanSetUserName = true, UserName = "******".GetFormat(nickName, (int)sex, DateTime.Now.ToString("ssff")), Password = "******".GetMD5By32(), NickName = nickName, UserAvatar = userAvatar, LastLoginTime = DateTime.Now }; return RegisterMemberByOpenLogin(user, deviceGpsTypeId, deviceGpsNo, deviceGpsSimNo, roleId); }
/// <summary> /// 编辑 /// </summary> /// <returns></returns> public ActionResult EditMember(EUser user) { if (user.Id == 0) { _aUserService.AddMember(user, Passport.User.Id, 3); //自动分配一个运营商客户 角色 return JsonResult(user, "添加成功!"); } else { _userService.SaveMember(user); return JsonResult(user, "保存成功!"); } }
public void AddUser(EUser user) { using (var dmTrans = _rep.GetTransaction()) { try { var tran = dmTrans.BeginTransaction(); if (_rep.Get<EUser>(p => p.UserName == user.UserName) != null) { throw new ArgumentException("存在相同用户名!"); }; user.UserAvatar = "/Content/Images/noPic.jpg"; user.Password = user.Password.GetMD5By32(); user.LastLoginTime = DateTime.Now; //添加用户 _rep.Add(user, tran); //添加车辆分组 _rep.Add(new EDeviceGroup() { DeviceGroupName = "默认分组", DeviceGroupOrderId = 0, IsRoot = true, UserId = user.Id }, tran); dmTrans.Commit(); //更新车辆分组缓存 _cacheService.RemoveByKey(Cdev.Core.Gps.CacheKey.Gps_DeviceGroups_All); } catch { dmTrans.Rollback(); throw; } } }
/// <summary> /// 保存 /// </summary> public void SaveUser(EUser user) { _rep.Save(user, p => p.Id == user.Id, p => new Columns(p.Address, p.Email, p.Fax, p.LastLoginTime, p.NickName, p.Mobile, p.QQ, p.Sex, p.UserStatus, p.Amount, p.IsSuperAdmin, p.UserAvatar)); }