public JsonResult GetTemplateNewOrgUnit() { var lic_act_types = repository.LicensedActivityType.GetNotDeletedItems().ToList(); OrgUnitViewModel result = new OrgUnitViewModel() { IsError = false, HasPeoples = false, Address = "", Name = "Новая", Id = 0, INN = "", Tel = "", Fax = "", EMail = "", KPP = "", LicenseActivityTypes = new List <LATForOrgUnitViewModel>(), OGRN = "", PostalCode = "", TagsTable = new ValueTagTableViewModel(0, EntitiesForTag.OrgUnit, repository) }; foreach (var l in lic_act_types) { result.LicenseActivityTypes.Add(new LATForOrgUnitViewModel() { Id = l.Id, Name = l.FullName, IsSelected = false }); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult GetOrgUnits() { var org_units = repository.OrgUnit.GetNotDeletedItems().Select(j => new { org_unit = j, Count_peoples = j.Peoples.Where(i => i.IsDeleted != true).Count() }).ToList(); var lic_act_types = repository.LicensedActivityType.GetNotDeletedItems().Select(j => new { lic_act_type = j, org_units = j.OrgUnits.ToList() }).ToList(); List <OrgUnitViewModel> result = new List <OrgUnitViewModel>(); foreach (var org_u in org_units) { OrgUnitViewModel now_ou = new OrgUnitViewModel() { EMail = org_u.org_unit.EMail, Fax = org_u.org_unit.Fax, Tel = org_u.org_unit.Tel, HasPeoples = org_u.Count_peoples > 0, Id = org_u.org_unit.Id, Name = org_u.org_unit.Name, Address = org_u.org_unit.Address, INN = org_u.org_unit.INN, KPP = org_u.org_unit.KPP, OGRN = org_u.org_unit.OGRN, PostalCode = org_u.org_unit.PostalCode, LicenseActivityTypes = new List <LATForOrgUnitViewModel>(), TagsTable = new ValueTagTableViewModel(org_u.org_unit.Id, EntitiesForTag.OrgUnit, repository) }; foreach (var l in lic_act_types) { now_ou.LicenseActivityTypes.Add(new LATForOrgUnitViewModel() { Id = l.lic_act_type.Id, Name = l.lic_act_type.FullName, IsSelected = l.org_units.FirstOrDefault(j => j.Id == org_u.org_unit.Id) != null }); } result.Add(now_ou); } return(Json(result, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 获取组织信息 /// </summary> /// <param name="unitID"></param> /// <returns></returns> public JsonResult GetOrgInfo(string unitID) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(true); OrgUnitViewModel model = new OrgUnitViewModel(); //判断是否有组织编辑、查看权限 OrgAclViewModel AclModel = GetUnitAcl(unitID); if (!AclModel.Edit && !AclModel.View) { result.Success = false; result.Message = "Orgnization.NoAcl"; return Json(result, JsonRequestBehavior.AllowGet); } model.Edit = AclModel.Edit; model.View = AclModel.View; if (string.IsNullOrEmpty(unitID)) { return Json(model, JsonRequestBehavior.AllowGet); } OThinker.Organization.OrganizationUnit unit = this.Engine.Organization.GetUnit(unitID) as OThinker.Organization.OrganizationUnit; if (unit == null) { return Json(model, JsonRequestBehavior.AllowGet); } model.ObjectID = unit.ObjectID; model.UnitName = unit.Name; model.Manager = unit.ManagerID; model.ParentUnit = unit.ParentID; model.SortKey = unit.SortKey; model.VisibleType = ((int)unit.Visibility).ToString(); model.WorkflowCode = unit.WorkflowCode; model.Calendar = unit.CalendarID; model.OrgCategory = unit.CategoryCode ?? ""; model.FullPath = this.Engine.Organization.GetFullName(unit.ObjectID); model.Description = unit.Description; result.Extend = model; return Json(result, JsonRequestBehavior.AllowGet); })); }
/// <summary> /// 保存/更新组织信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public JsonResult SaveOrgInfo(OrgUnitViewModel model) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(true, "msgGlobalString.SaveSucced"); if (string.IsNullOrEmpty(model.UnitName.Trim())) { result.Success = false; result.Message = "BizService.Msg4"; return Json(result); } //检查是否有编辑权限 //如果是新增,检查父节点的编辑权限,更新:检查当前节点的权限 if (!this.UserValidator.ValidateOrgEdit(string.IsNullOrEmpty(model.ObjectID) ? model.ParentUnit : model.ObjectID)) { result.Success = false; result.Message = "Orgnization.NoAcl"; return Json(result); } //检测同一节点下,名称不能重复 List <string> brothers = this.Engine.Organization.GetChildren(model.ParentUnit, OThinker.Organization.UnitType.OrganizationUnit, false, OThinker.Organization.State.Unspecified); Dictionary <string, string> dic = this.Engine.Organization.GetNames(brothers.ToArray()); if (dic.Where(d => d.Value == model.UnitName).Where(d => d.Key != model.ObjectID).Count() > 0) { result.Success = false; result.Message = "EditOrgUnit.OrgNameExisted"; result.Extend = ""; return Json(result); } //名称必须以字母开始,不让创建到数据库表字段时报错 //System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z\\u4e00-\\u9fa5][0-9a-zA-Z\\u4e00-\\u9fa5_]*$"); //if (!regex.Match(model.UnitName).Success) //{ // result.Success = false; // result.Message = "EditOrgUnit.NameInvalid"; // return Json(result); //} try { OThinker.Organization.VisibleType vt = (OThinker.Organization.VisibleType)Enum.Parse(typeof(OThinker.Organization.VisibleType), model.VisibleType); OThinker.Organization.OrganizationUnit unit = new OThinker.Organization.OrganizationUnit(); if (!string.IsNullOrEmpty(model.ObjectID)) { unit = (OThinker.Organization.OrganizationUnit) this.Engine.Organization.GetUnit(model.ObjectID); } unit.Name = model.UnitName; unit.ManagerID = model.Manager; unit.ParentID = model.ParentUnit; unit.SortKey = model.SortKey; unit.Visibility = vt; unit.WorkflowCode = model.WorkflowCode; unit.CalendarID = string.IsNullOrEmpty(model.Calendar) ? "" : model.Calendar; unit.CategoryCode = model.OrgCategory; unit.Description = model.Description; //ADD if (string.IsNullOrEmpty(model.ObjectID)) { this.Engine.Organization.AddUnit(this.UserValidator.UserID, unit); } //Update else { unit.ObjectID = model.ObjectID; this.Engine.Organization.UpdateUnit(this.UserValidator.UserID, unit); //如果是根节点更新菜单FunctionNode if (unit.IsRootUnit) { //FunctionNode node = this.Engine.FunctionAclManager.GetFunctionNode(unit.ObjectID); //node.DisplayName = unit.Name; //this.Engine.FunctionAclManager.UpdateFunctionNode(node); } } result.Extend = new { UnitID = unit.ObjectID };//返回前台更新TabID } catch (Exception ex) { result.Success = false; result.Message = "msgGlobalString.SaveFailed"; result.Extend = "," + ex.Message; } return Json(result); })); }
public JsonResult SaveOrgUnit(OrgUnitViewModel org_unit) { var lic_act_types = repository.LicensedActivityType.GetNotDeletedItems().ToList(); if (org_unit.Name == null || org_unit.Name == "") { org_unit.IsError = true; return(Json(org_unit, JsonRequestBehavior.AllowGet)); } if (org_unit.Id > 0) { OrgUnit ou = repository.OrgUnit.GetNotDeletedItems().FirstOrDefault(j => j.Id == org_unit.Id); try { if (ou == null) { org_unit.IsError = true; return(Json(org_unit, JsonRequestBehavior.AllowGet)); } var now_lic_act_types = ou.LicensedActivityTypes.Where(j => j.IsDeleted != true).ToList(); foreach (var l in org_unit.LicenseActivityTypes) { var now_lat = lic_act_types.First(j => j.Id == l.Id); if (l.IsSelected) { if (now_lic_act_types.FirstOrDefault(j => j.Id == l.Id) == null) { ou.LinkLicensedActivityType(now_lat, repository.logHelper); } } else { if (now_lic_act_types.FirstOrDefault(j => j.Id == l.Id) == null) { ou.UnLinkLicensedActivityType(now_lat, repository.logHelper); } } } var peoples_in_org_unit = ou.Peoples.ToList(); var first_new_license_Activity_type = org_unit.LicenseActivityTypes.First(); foreach (var p in peoples_in_org_unit) { if (org_unit.LicenseActivityTypes.FirstOrDefault(j => j.Id == p.LicensedActivityTypeId) == null) { p.LicensedActivityTypeId = first_new_license_Activity_type.Id; } } OrgUnit update_org_unit = new OrgUnit() { Id = org_unit.Id, Address = org_unit.Address, INN = org_unit.INN, KPP = org_unit.KPP, Name = org_unit.Name, OGRN = org_unit.OGRN, PostalCode = org_unit.PostalCode, EMail = org_unit.EMail, Fax = org_unit.Fax, Tel = org_unit.Tel }; repository.OrgUnit.Add(update_org_unit); org_unit.TagsTable.SaveTableTag(repository); repository.SaveChanges(); } catch (Exception exp) { org_unit.IsError = true; return(Json(org_unit, JsonRequestBehavior.AllowGet)); } } else { try { OrgUnit update_org_unit = new OrgUnit() { Id = org_unit.Id, Address = org_unit.Address, INN = org_unit.INN, KPP = org_unit.KPP, Name = org_unit.Name, OGRN = org_unit.OGRN, PostalCode = org_unit.PostalCode }; repository.OrgUnit.Add(update_org_unit); foreach (var l in org_unit.LicenseActivityTypes) { if (l.IsSelected) { var now_lat = lic_act_types.First(j => j.Id == l.Id); update_org_unit.LinkLicensedActivityType(now_lat, repository.logHelper); } } org_unit.TagsTable.SaveTableTag(repository); repository.SaveChanges(); org_unit.Id = update_org_unit.Id; } catch (Exception exp) { org_unit.IsError = true; return(Json(org_unit, JsonRequestBehavior.AllowGet)); } } org_unit.IsError = false; return(Json(org_unit, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> OrgChart(long?id, bool isUp = false) { List <OrgUnitViewModel> model = new List <OrgUnitViewModel>(); //check if new setup if (_context.OrgUnits.Count() == 0) { return(PartialView("_OrgChart", model)); } string rootCode; if (id.HasValue) { long rootId = id.Value; if (isUp) { var ou = await _context.OrgUnits.SingleOrDefaultAsync(b => b.Id == id); rootCode = ou.Code.Substring(0, ou.Code.Length - 3); } else { var ou = await _context.OrgUnits.SingleOrDefaultAsync(b => b.Id == rootId); rootCode = ou.Code; } } else { var ou = await _context.OrgUnits.FirstOrDefaultAsync(b => b.Code.Length == 2); rootCode = ou.Code; } //get down to the third level under the selected node int maxLevelLength = rootCode.Length + 6; var x = _context.OrgUnits.Include(b => b.OrgUnitType) .Where(b => !id.HasValue || (b.Code.StartsWith(rootCode) && b.Code.Length <= maxLevelLength)) .OrderBy(b => b.Code.Length).ThenBy(b => b.SortOrder); foreach (var x1 in x) { OrgUnitViewModel item = new OrgUnitViewModel(); item.OrgUnit = x1; //parent if (x1.Code.Length == 2) { item.ParentName = null; } else { item.ParentName = _context.OrgUnits.SingleOrDefault(b => b.Code == x1.Code.Substring(0, x1.Code.Length - 3)).Name; } //headed by var pos = await _context.Employments.Include(b => b.Employee).SingleOrDefaultAsync(b => b.OrgUnitId == x1.Id && b.IsActive && b.IsHead); if (pos != null) { item.HeadedByName = pos.Employee.FirstName + " " + pos.Employee.FamilyName; } else { item.HeadedByName = "VACANT"; } //totals item.TotalPositions = await _context.Positions.Where(b => b.OrgUnitId == id).CountAsync() + 1; item.TotalPersonnel = await _context.Employments.Where(b => b.OrgUnitId == id && b.IsActive).CountAsync(); item.TotalVacancy = await _context.Positions.Where(b => b.OrgUnitId == id).SumAsync(b => b.TotalVacant); model.Add(item); } return(PartialView("_OrgChart", model)); }