public void DeleteEntity() { var factory = new Data.RepositoryFactory(); Business.User userBiz = new Business.User(factory); var userFound = userBiz.Get(1); if (userFound == null) userFound = userBiz.Save(FakeEntities.Generator.CreateUser()); int id = userFound.Id; userBiz.Delete(userFound); var userDeleted = userBiz.Get(id); Assert.IsNull(userDeleted); }
public IActionResult Users() { string userId = Request.Querys("userid"); string type = Request.Querys("type"); string parentId = Request.Querys("orgparentid"); string orgId = Request.Querys("orgid"); string appId = Request.Querys("appid"); string tabId = Request.Querys("tabid"); string isAddUser = Request.Querys("isadduser"); Business.User user = new Business.User(); Model.User userModel = null; if (userId.IsGuid(out Guid guid)) { userModel = user.Get(guid); } if (null == userModel) { userModel = new Model.User() { Id = Guid.NewGuid(), Password = "******" }; ViewData["organizes"] = ""; ViewData["workgroups"] = ""; } else { ViewData["organizes"] = user.GetOrganizesShowHtml(userModel.Id); ViewData["workgroups"] = user.GetWorkGroupsName(userModel.Id); } string query = "userid=" + Request.Querys("userid") + "&orgparentid=" + Request.Querys("orgparentid") + "&type=" + Request.Querys("type") + "&showtype=" + Request.Querys("showtype") + "&appid=" + Request.Querys("appid") + "&tabid=" + Request.Querys("tabid"); ViewData["isAddUser"] = isAddUser; ViewData["refreshId"] = orgId.IsGuid() ? orgId : parentId; ViewData["queryString"] = Request.UrlQuery(); ViewData["prevUrl"] = ("Users?" + query).UrlEncode(); ViewData["returnUrl"] = Request.Querys("returnurl"); return(View(userModel)); }
public static void TestSelectSingle() { Test.Business.User UserBusiness = new Business.User(); Test.Model.User User = UserBusiness.Get(3); Console.WriteLine("用户名:" + User.LoginName + "\t" + "创建时间:" + User.CreateTime.ToString()); }
public string Tree1() { int showType = Request.Querys("showtype").ToString().ToInt(0);//显示类型 0组织架构 1角色组 string rootId = Request.Querys("rootid"); string searchWord = Request.Querys("searchword"); bool showUser = !"0".Equals(Request.Querys("shouser")); Business.Organize organize = new Business.Organize(); Business.User user = new Business.User(); Business.WorkGroup workGroup = new Business.WorkGroup(); Business.OrganizeUser organizeUser = new Business.OrganizeUser(); var organizeUserList = organizeUser.GetAll(); Guid orgRootId = organize.GetRootId(); Newtonsoft.Json.Linq.JArray jArray = new Newtonsoft.Json.Linq.JArray(); #region 搜索 if (!searchWord.IsNullOrWhiteSpace()) { Guid parentId = Guid.NewGuid(); if (1 == showType)//搜索工作组 { var workGroups = workGroup.GetAll().FindAll(p => p.Name.ContainsIgnoreCase(searchWord.Trim())); Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject() { { "id", parentId }, { "parentID", Guid.Empty }, { "title", "查询“" + searchWord + "”的结果" }, { "ico", "fa-search" }, { "link", "" }, { "type", 1 }, { "hasChilds", workGroups.Count } }; jArray.Add(jObject); Newtonsoft.Json.Linq.JArray jArray1 = new Newtonsoft.Json.Linq.JArray(); foreach (var group in workGroups) { Newtonsoft.Json.Linq.JObject jObject1 = new Newtonsoft.Json.Linq.JObject() { { "id", group.Id }, { "parentID", parentId }, { "title", group.Name }, { "ico", "fa-slideshare" }, { "link", "" }, { "type", 5 }, { "hasChilds", 0 } }; jArray1.Add(jObject1); } jObject.Add("childs", jArray1); } else //搜索组织和人员 { var organizes = organize.GetAll().FindAll(p => p.Name.ContainsIgnoreCase(searchWord.Trim())); var users = user.GetAll().FindAll(p => p.Name.ContainsIgnoreCase(searchWord.Trim())); Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject() { { "id", parentId }, { "parentID", Guid.Empty }, { "title", "查询“" + searchWord + "”的结果" }, { "ico", "fa-search" }, { "link", "" }, { "type", 1 }, { "hasChilds", organizes.Count + users.Count } }; jArray.Add(jObject); Newtonsoft.Json.Linq.JArray jArray1 = new Newtonsoft.Json.Linq.JArray(); foreach (var organizeModel in organizes) { Newtonsoft.Json.Linq.JObject jObject1 = new Newtonsoft.Json.Linq.JObject() { { "id", organizeModel.Id }, { "parentID", parentId }, { "title", organizeModel.Name }, { "ico", "" }, { "link", "" }, { "type", organizeModel.Type }, { "hasChilds", organize.HasChilds(organizeModel.Id) ? 1 : 0 } }; jArray1.Add(jObject1); } foreach (var userModel in users) { Newtonsoft.Json.Linq.JObject jObject1 = new Newtonsoft.Json.Linq.JObject() { { "id", userModel.Id }, { "parentID", parentId }, { "title", userModel.Name }, { "ico", "fa-user" }, { "link", "" }, { "userID", userModel.Id }, { "type", 4 }, { "hasChilds", 0 } }; jArray1.Add(jObject1); } jObject.Add("childs", jArray1); } return(jArray.ToString()); } #endregion #region 显示角色组 if (1 == showType) { var workgroups = workGroup.GetAll(); foreach (var workgroupModel in workgroups) { Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject() { { "id", workgroupModel.Id }, { "parentID", Guid.Empty }, { "title", workgroupModel.Name }, { "ico", "fa-slideshare" }, { "link", "" }, { "type", 5 }, { "hasChilds", 0 } }; jArray.Add(jObject); } return(jArray.ToString()); } #endregion if (rootId.IsNullOrWhiteSpace()) { rootId = orgRootId.ToString(); } #region 添加根节点 string[] rootIdArray = rootId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string root in rootIdArray) { if (root.IsGuid(out Guid guid))//组织机构 { var organizeModel = organize.Get(guid); if (null != organizeModel) { Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject() { { "id", organizeModel.Id }, { "parentID", organizeModel.ParentId }, { "title", organizeModel.Name }, { "ico", organizeModel.Id == orgRootId ? "fa-sitemap" : "" }, { "link", "" }, { "type", organizeModel.Type }, { "hasChilds", organize.HasChilds(organizeModel.Id) ? 1 : showUser?organize.HasUsers(organizeModel.Id) ? 1 : 0 : 0 } }; jArray.Add(jObject); } } else if (root.StartsWith(Business.Organize.PREFIX_USER))//人员 { var userModel = user.Get(root.RemoveUserPrefix().ToGuid()); if (null != userModel) { Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject() { { "id", userModel.Id }, { "parentID", Guid.Empty }, { "title", userModel.Name }, { "ico", "fa-user" }, { "link", "" }, { "type", 4 }, { "hasChilds", 0 } }; jArray.Add(jObject); } } else if (root.StartsWith(Business.Organize.PREFIX_RELATION))//兼职人员 { var organizeUserModel = organizeUser.Get(root.RemoveUserRelationPrefix().ToGuid()); if (null != organizeUserModel) { var userModel = user.Get(organizeUserModel.UserId); if (null != userModel) { Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject() { { "id", organizeUserModel.Id }, { "parentID", Guid.Empty }, { "title", userModel.Name + "<span style='color:#666;'>[兼任]</span>" }, { "ico", "fa-user" }, { "link", "" }, { "type", 6 }, { "userID", userModel.Id }, { "hasChilds", 0 } }; jArray.Add(jObject); } } } else if (root.StartsWith(Business.Organize.PREFIX_WORKGROUP))//工作组 { var workgroupModel = workGroup.Get(root.RemoveWorkGroupPrefix().ToGuid()); if (null != workgroupModel) { Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject() { { "id", workgroupModel.Id }, { "parentID", Guid.Empty }, { "title", workgroupModel.Name }, { "ico", "fa-slideshare" }, { "link", "" }, { "type", 5 }, { "hasChilds", workGroup.GetAllUsers(workgroupModel.Id).Count } }; jArray.Add(jObject); } } } #endregion #region 只有一个根时显示二级 if (rootIdArray.Length == 1) { string rootIdString = rootIdArray[0]; if (rootIdString.IsGuid(out Guid guid)) { var jObject0 = (Newtonsoft.Json.Linq.JObject)jArray[0]; Newtonsoft.Json.Linq.JArray jArray0 = new Newtonsoft.Json.Linq.JArray(); var childs = organize.GetChilds(guid); var organizeUser1 = organizeUserList.FindAll(p => p.OrganizeId == guid); foreach (var child in childs) { Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject() { { "id", child.Id }, { "parentID", child.ParentId }, { "title", child.Name }, { "ico", "" }, { "link", "" }, { "type", child.Type }, { "hasChilds", organize.HasChilds(child.Id) ? 1 : showUser?organize.HasUsers(child.Id) ? 1 : 0 : 0 } }; jArray0.Add(jObject); } if (showUser) { var users = organize.GetUsers(guid); foreach (var userModel in users) { var organizeUserModel1 = organizeUser1.Find(p => p.UserId == userModel.Id); bool isPartTime = organizeUserModel1.IsMain != 1;//是否是兼职 Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject() { { "id", isPartTime ? organizeUserModel1.Id : userModel.Id }, { "parentID", guid }, { "title", userModel.Name + (isPartTime ? "<span style='color:#666;'>[兼任]</span>" : "") }, { "ico", "fa-user" }, { "link", "" }, { "userID", userModel.Id }, { "type", isPartTime ? 6 : 4 }, { "hasChilds", 0 } }; jArray0.Add(jObject); } } jObject0.Add("childs", jArray0); } else if (rootIdString.StartsWith(Business.Organize.PREFIX_WORKGROUP)) { var jObject0 = (Newtonsoft.Json.Linq.JObject)jArray[0]; Newtonsoft.Json.Linq.JArray jArray0 = new Newtonsoft.Json.Linq.JArray(); var users = workGroup.GetAllUsers(rootIdString.RemoveWorkGroupPrefix().ToGuid()); foreach (var userModel in users) { Newtonsoft.Json.Linq.JObject jObject = new Newtonsoft.Json.Linq.JObject() { { "id", userModel.Id }, { "parentID", rootIdString.RemoveWorkGroupPrefix() }, { "title", userModel.Name }, { "ico", "fa-user" }, { "link", "" }, { "type", 4 }, { "hasChilds", 0 } }; jArray0.Add(jObject); } jObject0.Add("childs", jArray0); } } #endregion return(jArray.ToString()); }
public string SaveUser(Model.User userModel) { if (!ModelState.IsValid) { return(Tools.GetValidateErrorMessag(ModelState)); } Business.User user = new Business.User(); if (!"1".Equals(Request.Querys("isadduser")) && Request.Querys("userid").IsGuid(out Guid guid)) { var oldModel = user.Get(guid); string oldJSON = null == oldModel ? "" : oldModel.ToString(); user.Update(userModel); //同步企业微信人员 if (Config.Enterprise_WeiXin_IsUse) { try { new Business.EnterpriseWeiXin.Organize().UpdateUser(userModel); } catch (Exception e) { Business.Log.Add(e); } } Business.Log.Add("修改了人员-" + userModel.Name, type: Business.Log.Type.系统管理, oldContents: oldJSON, newContents: userModel.ToString()); } else { string orgId = Request.Querys("orgid"); if (orgId.IsGuid(out Guid orgId1)) { Model.OrganizeUser organizeUser = new Model.OrganizeUser { Id = Guid.NewGuid(), IsMain = 1, OrganizeId = orgId1, UserId = userModel.Id, Sort = new Business.OrganizeUser().GetMaxSort(orgId1) }; userModel.Password = user.GetInitPassword(userModel.Id); user.Add(userModel, organizeUser); //同步企业微信人员 if (Config.Enterprise_WeiXin_IsUse) { try { new Business.EnterpriseWeiXin.Organize().AddUser(userModel); } catch (Exception e) { Business.Log.Add(e); } } Business.Log.Add("添加了人员-" + userModel.Name, userModel.ToString() + "-" + organizeUser.ToString(), Business.Log.Type.系统管理); } else { return("未找到人员对应的组织架构"); } } return("保存成功!"); }