public SYS_UserDetailDTO GetUserInfo(string userCode) { int returnCode = CommonData.DbReturnCode.Succeed; SYS_UserDetailDTO userDto = new SYS_UserDetailDTO(); try { using (BaseDao context = new BaseDao()) { ms_users user = context.ms_users.Where(c => c.Code == userCode).FirstOrDefault(); if (user != null) { userDto.ID = user.ID; userDto.FullName = user.DisplayName; userDto.UserName = user.Code; userDto.Status = user.Status; } } } catch (Exception ex) { returnCode = this.ProcessDbException(ex); } return(userDto); }
public int DisconnectData(List <int> listDisconnectData) { int returnCode = CommonData.DbReturnCode.Succeed; try { using (BaseDao context = new BaseDao()) { foreach (var id in listDisconnectData) { ms_users user = context.ms_users.FirstOrDefault(ig => ig.ID.Equals(id)); if (user != null) { //Set null for IPAddress & ComputerName user.IPAddress = CommonData.StringEmpty; user.ComputerName = CommonData.StringEmpty; user.LogonState = CommonData.LogonState.DisByAdmin; } else { return(CommonData.DbReturnCode.DataNotFound); } } //Save to database returnCode = context.Saves(); } } catch (Exception ex) { returnCode = this.ProcessDbException(ex); } return(returnCode); }
public int SelectUserSkinData(string userCode, out string skin) { //dtResult = new DataTable(); int returnCode = CommonData.DbReturnCode.Succeed; skin = CommonData.StringEmpty; try { using (BaseDao context = new BaseDao()) { ms_users user = context.ms_users.FirstOrDefault(us => us.Code == userCode); if (user != null) { skin = user.UserSkin; } } } catch (Exception ex) { returnCode = this.ProcessDbException(ex); } return(returnCode); }
/// <summary> /// Update user's skin /// </summary> /// <param name="userCode"></param> /// <param name="skin"></param> /// <returns></returns> public int UpdateUserSkin(string userCode, string skin) { int returnCode = CommonData.DbReturnCode.Succeed; try { using (BaseDao context = new BaseDao()) { ms_users user = context.ms_users.FirstOrDefault(us => us.Code == userCode); if (user != null) { user.UserSkin = skin; //Save context.Saves(); } } } catch (Exception ex) { returnCode = this.ProcessDbException(ex); } return(returnCode); }
public int UpdateData(SYS_UserDetailDTO _UserUpdateDto) { int returnCode = CommonData.DbReturnCode.Succeed; try { using (BaseDao context = new BaseDao()) { context.BeginTransaction(); #region Update User ms_users _users = context.ms_users.FirstOrDefault(u => u.ID.Equals(_UserUpdateDto.ID)); if (_users != null) { _users.ID = _UserUpdateDto.ID; _users.Code = _UserUpdateDto.UserName; _users.DisplayName = _UserUpdateDto.FullName; _users.Status = _UserUpdateDto.Status; _users.Password = _UserUpdateDto.Password; //Save to database //returnCode = context.Saves(); returnCode = context.Saves(CommonData.FunctionGr.SY_Users, CommonData.Action.Update, new { _users.Code, _users.DisplayName, _users.Status }, typeof(ms_users).Name); //Check if error occur if (returnCode != CommonData.DbReturnCode.Succeed) { context.Rollback(); return(returnCode); } } else { returnCode = CommonData.DbReturnCode.DataNotFound; } #endregion Update User #region Delete GroupAssign var _groupsassign = context.ms_groupsassign.AsQueryable(); _groupsassign = _groupsassign.Where(ga => ga.UserCode.Equals(_UserUpdateDto.UserName)); foreach (var ga in _groupsassign) { context.DeleteObject(ga); } #endregion Delete GroupAssign #region Insert data to GroupAssign Table ms_groupsassign groupsassign = null; foreach (var item in _UserUpdateDto.UserGroups) { groupsassign = new ms_groupsassign(); groupsassign.UserCode = _UserUpdateDto.UserName; groupsassign.GroupCode = item.Code; groupsassign.SystemData = "0"; context.ms_groupsassign.AddObject(groupsassign); returnCode = context.Saves(); } if (returnCode != CommonData.DbReturnCode.Succeed) { context.Rollback(); return(returnCode); } //Commit to database if (returnCode == CommonData.DbReturnCode.Succeed) { context.Commit(); } #endregion Insert data to GroupAssign Table } } catch (Exception ex) { returnCode = this.ProcessDbException(ex); } return(returnCode); }
public int InsertData(SYS_UserDetailDTO insertUserDto) { int returnCode = CommonData.DbReturnCode.Succeed; try { using (BaseDao context = new BaseDao()) { context.BeginTransaction(); #region Insert data to User Table //table user ms_users _users = new ms_users(); _users.Code = insertUserDto.UserName; _users.DisplayName = insertUserDto.FullName; _users.Password = insertUserDto.Password; _users.Profile = insertUserDto.Profile; _users.Status = insertUserDto.Status; _users.SystemData = "0"; //Add user context.ms_users.AddObject(_users); //Save to database //returnCode = context.Saves(); returnCode = context.Saves(CommonData.FunctionGr.SY_Users, CommonData.Action.Insert, new { _users.Code, _users.DisplayName, _users.Password, _users.Profile, _users.Status, _users.SystemData }, typeof(ms_users).Name); if (returnCode != CommonData.DbReturnCode.Succeed) { context.Rollback(); return(returnCode); } #endregion Insert data to User Table #region Insert data to GroupAssign Table ms_groupsassign _groupsassign = null; foreach (var item in insertUserDto.UserGroups) { _groupsassign = new ms_groupsassign(); _groupsassign.UserCode = insertUserDto.UserName; _groupsassign.GroupCode = item.Code; _groupsassign.SystemData = "0"; context.ms_groupsassign.AddObject(_groupsassign); returnCode = context.Saves(); } if (returnCode != CommonData.DbReturnCode.Succeed) { context.Rollback(); return(returnCode); } //Commit to database if (returnCode == CommonData.DbReturnCode.Succeed) { context.Commit(); } #endregion Insert data to GroupAssign Table } } catch (Exception ex) { returnCode = this.ProcessDbException(ex); } return(returnCode); }