public static bool UpdateGroup(USER_GROUP group) { group.MODIFY_BY = ClientSessionService.GetSession.loginedUser.ID; group.MODIFY_DATE = DateTime.Now; try { return(WillORM.UpdateRecord(group)); } catch { return(false); } }
public bool UpdateGroup(int groupId, string groupName, List <int> userId, out string mess) { try { if (!Query.Any(n => n.GROUP_NAME.ToUpper() == groupName.ToUpper().Trim() && n.ID != groupId)) { var userGroupSrv = IoC.Resolve <IUSER_GROUPService>(); BeginTran(); var lstUserIdOfOldGroup = userGroupSrv.Query.Where(n => n.GROUP_ID == groupId).ToList(); foreach (var item in lstUserIdOfOldGroup) { userGroupSrv.Delete(item); userGroupSrv.CommitChanges(); } var group = Getbykey(groupId); try { group.GROUP_NAME = groupName; } catch (Exception e) { log.ErrorFormat("message: {0}{1} stacktrace: {2}", e.Message, Environment.NewLine, e.StackTrace); } //Clear(); Update(group); CommitChanges(); foreach (var id in userId) { var userGroup = new USER_GROUP() { USER_ID = id, GROUP_ID = group.ID }; userGroupSrv.CreateNew(userGroup); CommitChanges(); } CommitTran(); mess = "Cập nhật nhóm người dùng thành công"; return(true); } else { mess = "Tên nhóm này đã tồn tại, hãy thử lại với tên khác"; return(false); } } catch (Exception ex) { RolbackTran(); log.Error(ex.StackTrace); mess = "Lỗi hệ thống, vui lòng thử lại sau"; return(false); } }
public AccessViewModel() { group = new List <USER_GROUP>(); inactiveList = new List <int>(); newGroup = new USER_GROUP(); SelectedGroup = Constant.DEF_INT; groupRights = new List <USER_GROUP_RIGHT>(); groupUserlist = new List <GroupUserView>(); }
public bool AddNewGroup(string groupName, List <int> userId, out string mess) { var nguoidungs = ((EISContext)FXContext.Current).CurrentNguoidung; var UserDataService = IoC.Resolve <IuserService>(); var userIdData = UserDataService.Query.Where(o => o.username == nguoidungs.TENDANGNHAP).FirstOrDefault().userid; try { if (!Query.Any(n => n.GROUP_NAME.ToUpper() == groupName.ToUpper().Trim() && n.USER_ID == userIdData))//userId.Contains(n.USER_ID) { var userGroupSrv = IoC.Resolve <IUSER_GROUPService>(); BeginTran(); var group = new NHOM_USER() { GROUP_NAME = groupName.Trim(), USER_ID = Convert.ToInt32(nguoidungs.ID), }; CreateNew(group); CommitChanges(); foreach (var id in userId) { var userGroup = new USER_GROUP() { USER_ID = id, GROUP_ID = group.ID }; userGroupSrv.CreateNew(userGroup); CommitChanges(); } CommitTran(); mess = "Thêm mới nhóm người dùng thành công"; return(true); } else { mess = "Tên nhóm này đã tồn tại, hãy thử lại với tên khác"; return(false); } } catch (Exception ex) { RolbackTran(); log.Error(ex.StackTrace); mess = "Lỗi hệ thống, vui lòng thử lại sau"; return(false); } }
public messageModel saveUserRole(RoleViewModel role) { messageModel result = new messageModel(); try { if (String.IsNullOrEmpty(role.user_id)) { throw new Exception("Unauthorized Access"); } var userId = JwtHelper.GetUserIdFromToken(role.user_id); if (String.IsNullOrEmpty(userId)) { throw new Exception("Unauthorized Access"); } using (var context = new StandardCanEntities()) { var dt = DateTime.Now; if (String.IsNullOrEmpty(role.usergroup_id)) { var checkName = context.USER_GROUP.SingleOrDefault(a => a.Group_Name.ToUpper() == role.usergroup_Desc.ToUpper()); if (checkName != null) { throw new Exception("Data is duplicate"); } USER_GROUP uSER_GROUP = new USER_GROUP(); uSER_GROUP.Group_Name = role.usergroup_Desc.ToUpper(); uSER_GROUP.Active = role.active ?? false; context.USER_GROUP.Add(uSER_GROUP); context.SaveChanges(); if (role.program_list != null) { foreach (var item in role.program_list) { USER_ROLE data = new USER_ROLE(); data.Group_ID = uSER_GROUP.Group_ID.ToString(); data.Program_ID = item.program_id; data.Active = role.active ?? false; data.Create_Date = dt; data.Create_By = Convert.ToInt32(userId); data.Update_Date = dt; data.Update_By = Convert.ToInt32(userId); context.USER_ROLE.Add(data); context.SaveChanges(); } } } else { var checkName = context.USER_GROUP.SingleOrDefault(a => a.Group_Name.ToUpper() == role.usergroup_Desc.ToUpper() && a.Group_ID.ToString() != role.usergroup_id); if (checkName != null) { throw new Exception("Data is duplicate"); } var userGroupDetail = context.USER_GROUP.SingleOrDefault(a => a.Group_ID.ToString() == role.usergroup_id); if (userGroupDetail == null) { throw new Exception("Data is not found"); } userGroupDetail.Group_Name = role.usergroup_Desc.ToUpper(); userGroupDetail.Active = role.active ?? false; context.SaveChanges(); var roleOldList = context.USER_ROLE.Where(a => a.Group_ID == role.usergroup_id).ToList(); context.USER_ROLE.RemoveRange(roleOldList); context.SaveChanges(); if (role.program_list != null) { foreach (var item in role.program_list) { USER_ROLE data = new USER_ROLE(); data.Group_ID = userGroupDetail.Group_ID.ToString(); data.Program_ID = item.program_id; data.Active = role.active ?? false; data.Create_Date = dt; data.Create_By = Convert.ToInt32(userId); data.Update_Date = dt; data.Update_By = Convert.ToInt32(userId); context.USER_ROLE.Add(data); context.SaveChanges(); } } } } result.status = "S"; result.message = ""; } catch (Exception ex) { result.status = "E"; result.message = ex.Message.ToString(); } return(result); }