public JsonResult DoReset(string NewCode) { string ListIDs = Request["ListIDs"]; if (string.IsNullOrWhiteSpace(ListIDs)) { return(Json("")); } var list = entities.Set <S_A_User>().ToList(); var List = list.Where(t => ListIDs.Contains(t.ID)).ToList(); foreach (var item in List) { item.IsDeleted = "0"; item.DeleteTime = null; if (list.Any(a => a.ID != item.ID && a.Code == NewCode && a.IsDeleted == "0")) { throw new BusinessValidationException("账号【" + NewCode + "】已经存在"); } item.Code = NewCode; #region 部门 if (!string.IsNullOrWhiteSpace(item.DeptFullID)) { string[] OrgIDs = item.DeptFullID.Split('.'); foreach (var OrgID in OrgIDs) { var relation = item.S_A__OrgUser.Where(t => t.OrgID == OrgID).FirstOrDefault(); if (relation == null) { relation = new S_A__OrgUser(); relation.UserID = item.ID; relation.OrgID = OrgID; item.S_A__OrgUser.Add(relation); } } } else { var relation = item.S_A__OrgUser.Where(t => t.OrgID == Config.Constant.OrgRootID).FirstOrDefault(); if (relation == null) { relation = new S_A__OrgUser(); relation.UserID = item.ID; relation.OrgID = Config.Constant.OrgRootID; item.S_A__OrgUser.Add(relation); } } #endregion } entities.SaveChanges(); return(Json("")); }
//更新雇员加入系统用户 public void EmployeeUpdateToUser(T_Employee employee) { BaseEntities baseEntities = FormulaHelper.GetEntities <BaseEntities>(); HREntities entities = FormulaHelper.GetEntities <HREntities>(); var enumService = FormulaHelper.GetService <IEnumService>(); S_A_User user = baseEntities.Set <S_A_User>().Find(employee.UserID); if (user == null) { user = baseEntities.Set <S_A_User>().FirstOrDefault(c => c.Code == employee.Code && c.IsDeleted == "0"); } employee.UserID = user.ID; user.WorkNo = employee.Code; //user.Code = employee.Code; user.Name = employee.Name; user.IsDeleted = employee.IsDeleted; user.Sex = employee.Sex; user.ModifyTime = DateTime.Now; if (employee.Address != null) { user.Address = employee.Address; } if (employee.Email != null) { user.Email = employee.Email; } if (employee.OfficePhone != null) { user.Phone = employee.OfficePhone; } if (employee.MobilePhone != null) { user.MobilePhone = employee.MobilePhone; } S_A_Org org = null; user.S_A__OrgUser.RemoveWhere(c => c.S_A_Org.Type != "Post"); List <string> orgIDList = user.S_A__OrgUser.Select(a => a.OrgID).ToList(); List <S_A_Org> orgList = baseEntities.Set <S_A_Org>().Where(a => a.IsDeleted == "0").ToList(); if (employee.DeptID != null) { org = orgList.Where(c => c.ID == employee.DeptID).FirstOrDefault(); } if (org == null) { org = orgList.Where(c => c.ParentID == null || c.ParentID == "").FirstOrDefault(); } if (org != null) { user.DeptID = org.ID; user.DeptName = org.Name; user.DeptFullID = org.FullID; string companyID = ""; string companyName = ""; //逆序判断类型是否为集团/公司 string[] orgIDs = org.FullID.Split('.'); var orgs = orgList.Where(c => orgIDs.Contains(c.ID)).ToDictionary <S_A_Org, string>(d => d.ID); for (var i = orgIDs.Length; i > 0; i--) { if ((orgs[orgIDs[i - 1]].Type ?? "none").IndexOf("Company") > -1) { companyID = orgs[orgIDs[i - 1]].ID; companyName = orgs[orgIDs[i - 1]].Name; break; } } user.CorpID = companyID; user.CorpName = companyName; } if (!string.IsNullOrEmpty(user.DeptFullID)) { foreach (var id in user.DeptFullID.Split('.')) { if (!orgIDList.Contains(id)) { S_A__OrgUser orgUser = new S_A__OrgUser(); orgUser.OrgID = id; orgUser.UserID = user.ID; baseEntities.Set <S_A__OrgUser>().Add(orgUser); orgIDList.Add(id); } } } if (!string.IsNullOrEmpty(employee.ParttimeDeptID)) { foreach (var id in employee.ParttimeDeptID.Split(',')) { var parttimeOrg = orgList.FirstOrDefault(c => c.ID == employee.DeptID); if (parttimeOrg != null) { foreach (var parttimeOrgID in parttimeOrg.FullID.Split('.')) { if (!orgIDList.Contains(parttimeOrgID)) { S_A__OrgUser orgUser = new S_A__OrgUser(); orgUser.OrgID = parttimeOrgID; orgUser.UserID = user.ID; baseEntities.Set <S_A__OrgUser>().Add(orgUser); orgIDList.Add(id); } } } } } //修改用户图片 S_A_UserImg userImg = null; List <S_A_UserImg> userImgList = baseEntities.Set <S_A_UserImg>().Where(c => c.UserID == user.ID).ToList(); if (userImgList.Count > 0) { userImg = userImgList.FirstOrDefault(); } else { userImg = new S_A_UserImg() { ID = FormulaHelper.CreateGuid(), UserID = user.ID }; baseEntities.Set <S_A_UserImg>().Add(userImg); } if (employee.Portrait != null) { userImg.Picture = employee.Portrait; } if (employee.SignImage != null) { userImg.SignImg = employee.SignImage; } if (employee.SignDwg != null) { userImg.DwgFile = employee.SignDwg; } entities.SaveChanges(); baseEntities.SaveChanges(); }
public override JsonResult Save() { var user = base.UpdateEntity <S_A_User>(); if (entities.Set <S_A_User>().Count(c => c.Code == user.Code && c.ID != user.ID) > 0) { throw new Exception("用户账号不能重复"); } if (!string.IsNullOrEmpty(user.RTX)) { if (entities.Set <S_A_User>().Count(c => c.RTX == user.RTX && c.ID != user.ID) > 0) { throw new Exception("RTX帐号不能重复"); } } user.Code = user.Code.Trim(); if (string.IsNullOrEmpty(user.Password)) { user.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(user.Code.ToLower(), "SHA1"); } if (user.S_A__OrgUser.Count == 0) { user.S_A__OrgUser.Add(new S_A__OrgUser() { UserID = user.ID, OrgID = Config.Constant.OrgRootID }); } var currentUser = FormulaHelper.GetUserInfo(); if (user._state == EntityStatus.added.ToString()) { if (string.IsNullOrEmpty(user.CorpID)) { var rootOrg = entities.Set <S_A_Org>().FirstOrDefault(c => string.IsNullOrEmpty(c.ParentID)); user.CorpID = rootOrg.ID; user.CorpName = rootOrg.Name; } if (string.IsNullOrEmpty(user.CorpName)) { var org = entities.Set <S_A_Org>().SingleOrDefault(c => c.ID == user.CorpID); user.CorpName = org.Name; } if (!string.IsNullOrEmpty(user.CorpID)) { S_A__OrgUser orgUser = user.S_A__OrgUser.FirstOrDefault(c => c.OrgID == user.CorpID); if (orgUser == null) { orgUser = new S_A__OrgUser(); orgUser.OrgID = user.CorpID; orgUser.UserID = user.ID; entities.Set <S_A__OrgUser>().Add(orgUser); } } } return(base.JsonSave <S_A_User>(user)); }
//新添雇员加入系统用户 public void EmployeeAddToUser(T_Employee employee, string Password) { if (employee.IsDeleted == "1") { return; } BaseEntities baseEntities = FormulaHelper.GetEntities <BaseEntities>(); HREntities entities = FormulaHelper.GetEntities <HREntities>(); //添加新用户 S_A_User user = new S_A_User() { ID = FormulaHelper.CreateGuid(), Code = employee.Code, Name = employee.Name, WorkNo = employee.Code, Address = employee.Address, Email = employee.Email, Password = Password, Sex = employee.Sex, InDate = employee.JoinCompanyDate, Phone = employee.OfficePhone, MobilePhone = employee.MobilePhone, ModifyTime = DateTime.Now, IsDeleted = "0" }; baseEntities.Set <S_A_User>().Add(user); //反写userID employee.UserID = user.ID; List <string> orgIDList = new List <string>(); List <S_A_Org> orgList = baseEntities.Set <S_A_Org>().Where(a => a.IsDeleted == "0").ToList(); S_A_Org org = null; if (employee.DeptID != null) { org = orgList.Where(c => c.ID == employee.DeptID && c.IsDeleted == "0").FirstOrDefault(); } if (org == null) { org = orgList.Where(c => c.ParentID == null || c.ParentID == "").FirstOrDefault(); } if (org != null) { user.DeptID = org.ID; user.DeptName = org.Name; user.DeptFullID = org.FullID; string companyID = ""; string companyName = ""; //逆序判断类型是否为集团/公司 string[] orgIDs = org.FullID.Split('.'); var orgs = orgList.Where(c => orgIDs.Contains(c.ID)).ToDictionary <S_A_Org, string>(d => d.ID); for (var i = orgIDs.Length; i > 0; i--) { if ((orgs[orgIDs[i - 1]].Type ?? "none").IndexOf("Company") > -1) { companyID = orgs[orgIDs[i - 1]].ID; companyName = orgs[orgIDs[i - 1]].Name; break; } } user.CorpID = companyID; user.CorpName = companyName; } if (!string.IsNullOrEmpty(user.DeptFullID)) { foreach (var id in user.DeptFullID.Split('.')) { if (!orgIDList.Contains(id)) { S_A__OrgUser orgUser = new S_A__OrgUser(); orgUser.OrgID = id; orgUser.UserID = user.ID; baseEntities.Set <S_A__OrgUser>().Add(orgUser); orgIDList.Add(id); } } } if (!string.IsNullOrEmpty(employee.ParttimeDeptID)) { foreach (var id in employee.ParttimeDeptID.Split(',')) { var parttimeOrg = orgList.FirstOrDefault(c => c.ID == employee.DeptID); if (parttimeOrg != null) { foreach (var parttimeOrgID in parttimeOrg.FullID.Split('.')) { if (!orgIDList.Contains(parttimeOrgID)) { S_A__OrgUser orgUser = new S_A__OrgUser(); orgUser.OrgID = parttimeOrgID; orgUser.UserID = user.ID; baseEntities.Set <S_A__OrgUser>().Add(orgUser); orgIDList.Add(id); } } } } } //添加用户图片 S_A_UserImg userImg = new S_A_UserImg() { ID = FormulaHelper.CreateGuid(), UserID = user.ID, Picture = employee.Portrait, SignImg = employee.SignImage }; baseEntities.Set <S_A_UserImg>().Add(userImg); entities.SaveChanges(); baseEntities.SaveChanges(); }