public Staff GetStaff(int id) { using (var dbContext = new HRDbContext()) { return(dbContext.Staffs.Include("Branch").FirstOrDefault(a => a.ID == id)); } }
public void DeleteStaff(List <int> ids) { using (var dbContext = new HRDbContext()) { dbContext.Staffs.Where(u => ids.Contains(u.ID)).Delete(); } }
public IList <HR_ORG_Organization> GetChildOrg(Guid legalId, Guid parentId, bool includeSelf = true) { List <HR_ORG_Organization> lst = new List <HR_ORG_Organization>(); using (var dc = new HRDbContext()) { var org = dc.HR_ORG_Organization.Where(t => !t.IsDeleted && t.OrganizationID == parentId); if (legalId != Guid.Empty) { org = org.Where(t => t.LegalEntityID == legalId); } if (!org.Any()) { return(new List <HR_ORG_Organization>()); } var listAllOrg = dc.HR_ORG_Organization.Where(t => !t.IsDeleted); if (legalId != Guid.Empty) { listAllOrg = listAllOrg.Where(t => t.LegalEntityID == legalId); } if (includeSelf) { lst.Add(org.First()); } lst.AddRange(GetChild(listAllOrg.ToList(), org.First().OrganizationID).ToList()); } return(lst); }
public Branch GetBranch(int id) { using (var dbContext = new HRDbContext()) { return(dbContext.Find <Branch>(id)); } }
public static void CreateInitialDatabase() { using (var context = new HRDbContext()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // Create the initial Data Guid id = Guid.Parse("d9742d91-dc17-4be7-a715-55cc9d231c55"); Employee emp = new Employee() { EmployeeID = id, EmployeeName = "Mohamed Taha", Birthdate = new DateTime(1982, 6, 1), HiringDate = new DateTime(2010, 6, 1), Gender = true, Mobile = "66130236", ProfilePicture = id.ToString() + ".jpg", Email = "*****@*****.**", EmployeeAddress = new List <EmployeeAddress>() { new EmployeeAddress() { EmployeeID = id, RecordID = Guid.NewGuid(), AddressLine1 = "Bin Dinar st.", AddressLine2 = "Building # 11", City = "Al-Sadd", CountryID = "QA", ContactName = "Mohamed Taha" }, new EmployeeAddress() { EmployeeID = id, RecordID = Guid.NewGuid(), AddressLine1 = "Ain Khaled", AddressLine2 = "Building # 7", City = "Doha", CountryID = "QA", ContactName = "Mohamed Taha" } } }; //var repo = new EmployeeRepository(context); //repo.Add(emp); context.Employee.Add(emp); Department dep = new Department() { DepartmentID = Guid.NewGuid(), DepartmentName = "IT department" }; context.Department.Add(dep); context.SaveChanges(); } }
public static void SeedHostDb(HRDbContext context) { context.SuppressAutoSetTenantId = true; // Host seed new InitialHostDbBuilder(context).Create(); // Default tenant seed (in host database). new DefaultTenantBuilder(context).Create(); new TenantRoleAndUserBuilder(context, 1).Create(); }
public List <SelectItem> GetAllOfficeAreas() { var tenantId = this.GetCurrentCredential().TenantGuid(); using (var dc = new HRDbContext()) { var query = dc.HR_EMP_OfficeArea.Where(c => c.TenantID == tenantId); var items = query.Select(item => new SelectItem { ID = item.AreaID.ToString(), Name = item.AreaName, Code = item.AreaCode }).ToList(); return(items); } }
public static void Main(string[] args) { IWebHost webHost = CreateWebHostBuilder(args).Build(); using (IServiceScope scope = webHost.Services.CreateScope()) { using (HRDbContext dbContext = scope.ServiceProvider.GetRequiredService <HRDbContext>()) { Seed.InvokeAsync(scope, dbContext).Wait(); } } webHost.Run(); }
/// <summary> /// 返回树形组织结构,根节点RootBranch(id=0, ParentId=0),其下Staff和Branch为未分配的,根节点下的第一个节点为TopBranch(id=1, ParantId=0),其他ParentId=0的归为RootBranch下 /// </summary> /// <returns></returns> public Branch GetOrg() { using (var dbContext = new HRDbContext()) { var branchs = dbContext.Branchs.ToList(); var staffs = dbContext.Staffs.ToList(); var branch = new Branch(); AppendBranch(branchs, staffs, branch); return(branch); } }
public void SaveEmployeeUser(EmployeeUser user) { if (user.Id == Guid.Empty) { throw new BusinessException(this.Exception("Id 不能为空")); } if (string.IsNullOrEmpty(user.LoginName)) { throw new BusinessException(this.Exception("登陆名不能为空")); } var credential = this.GetCurrentCredential(); var tenantId = credential.TenantGuid(); var permissionService = this.GetBizService <IBizPermissionService>(); var sysUser = new SysUser { Id = user.Id.ToString(), LoginName = user.LoginName, Name = user.Name, UserType = "employee", Password = user.Password, UserNo = user.EmployeeNo, Email = user.Email, Mobile = user.Mobile, UserStatus = user.EmployeeStatus, UserPhotoId = user.PhotoAttachmentID, PositionId = user.MainPositionId.ToString(), OrgId = user.OrgId.ToString(), DataSource = "ERM_HR", ResState = user.Enable ? 0 : 1, BelongOrgs = user.Positions.ToList(), DataRoot = user.LegalId.ToString(), TenantId = user.TenantId.ToString() }; try { using (var dc = new HRDbContext()) { var roleList = (from p in user.Positions join r in dc.HR_ORG_PositionRoleList on p equals r.PositionID.ToString() select r.RoleID.ToString()).Distinct().ToList(); sysUser.RoleList = roleList; } permissionService.SaveUser(sysUser); } catch (Exception e) { throw new BusinessException(this.Exception(e.Message)); } }
public void SaveStaff(Staff staff) { using (var dbContext = new HRDbContext()) { if (staff.ID > 0) { dbContext.Update <Staff>(staff); } else { dbContext.Insert <Staff>(staff); } } }
public void SaveBranch(Branch branch) { using (var dbContext = new HRDbContext()) { if (branch.ID > 0) { dbContext.Update <Branch>(branch); } else { dbContext.Insert <Branch>(branch); } } }
/// <summary> /// 保存树形组织结构(刷全表数据/BatchUpdate),先取出来所有的Branch,Staff的ParentId为0,然后在根据RootBranch的树形结构赋对应的值 /// </summary> /// <param name="rootBranch"></param> public void SaveOrg(Branch rootBranch) { using (var dbContext = new HRDbContext()) { var branchs = dbContext.Branchs.ToList(); branchs.ForEach(b => b.ParentId = 0); var staffs = dbContext.Staffs.ToList(); staffs.ForEach(s => s.BranchId = 0); UpdateOrg(branchs, staffs, rootBranch); dbContext.SaveChanges(); } }
public IEnumerable <Branch> GetBranchList(BranchRequest request = null) { request = request ?? new BranchRequest(); using (var dbContext = new HRDbContext()) { IQueryable <Branch> branchs = dbContext.Branchs; if (!string.IsNullOrEmpty(request.Name)) { branchs = branchs.Where(u => u.Name.Contains(request.Name)); } return(branchs.OrderByDescending(u => u.ID).ToPagedList(request.PageIndex, request.PageSize)); } }
public BusinessResult GetOrgTree(BusinessContext context) { var notLimitLegal = "1".Equals(context.Request["notLimitLegal"]); var tenantId = context.Credential.TenantGuid(); var legal = context.Credential.LegalGuid(); using (var dc = new HRDbContext()) { var orgdata = from org in dc.HR_ORG_Organization where org.TenantID == tenantId && !org.IsDeleted && !org.IsDisabled select new { org.OrganizationID, org.OrganizationName, org.OrganizationType, org.ParentID, org.CodePath, org.OrganizationCode, org.Sequence, org.LegalEntityID }; if (!notLimitLegal) { orgdata = orgdata.Where(t => t.LegalEntityID == legal); } var data = orgdata.OrderBy(t => t.OrganizationCode.Length).ThenBy(t => t.Sequence).ThenBy(t => t.OrganizationCode).ToArray(); var listtree = data.Select(item => new BM_TreeModel { id = item.OrganizationID.ToString(), text = item.OrganizationName, pid = (item.LegalEntityID == legal && item.OrganizationType == "3|HR_ORG_OrganizationType" && !notLimitLegal) ? null : item.ParentID.ToString(), code = item.OrganizationCode, Sequence = item.Sequence, attributes = new Dictionary <string, string>() { { "CodePath", item.CodePath }, { "OrgType", item.OrganizationType } } }).ToArray(); return(this.CreateResult(BusinessStatusCode.OK, BM_TreeModel.CreateTree(listtree))); } }
public List <SysOrgItem> GetOrgHeadCountData(string category = null) { List <string> lstEmpStatus = new List <string>() { "0|" + DictConstants.HR_EMP_EmpStatus, "2|" + DictConstants.HR_EMP_EmpStatus }; using (var dc = new HRDbContext()) { var tenantId = this.GetCurrentCredential().TenantGuid(); //TODO:根据数据权限限制法人实体 var orgdata = from org in dc.HR_ORG_Organization where !org.IsDeleted && !org.IsDisabled && org.TenantID == tenantId orderby org.ParentID, org.Sequence select new { org.OrganizationID, org.OrganizationName, org.OrganizationCode, org.OrganizationType, org.CodePath, org.ParentID, org.LegalEntityID, org.TenantID, HeadCount = dc.HR_EMP_Employee.Count( t => !t.IsDeleted && t.OrganizationCode.StartsWith(org.OrganizationCode) && lstEmpStatus.Contains(t.EmpStatus)) }; return(orgdata.ToArray().Select(n => new SysOrgItem() { Id = n.OrganizationID.ToString(), Name = n.OrganizationName, Code = n.OrganizationCode, ParentId = n.ParentID.ToString(), OrganiztionType = n.OrganizationType, CodePath = n.CodePath, LegalId = n.LegalEntityID, TenantId = n.TenantID, Data = new Core.DictTable { { "HeadCount", n.HeadCount } }, }).ToList()); } }
public List <SelectItem> GetOfficeAreas(List <Guid> areaIds) { var list = new List <SelectItem>(); if (areaIds == null || areaIds.Count == 0) { return(list); } var tenantId = this.GetCurrentCredential().TenantGuid(); using (var dc = new HRDbContext()) { var query = dc.HR_EMP_OfficeArea.Where(c => c.TenantID == tenantId && areaIds.Contains(c.AreaID)); var items = query.Select(item => new SelectItem { ID = item.AreaID.ToString(), Name = item.AreaName, Code = item.AreaCode }).ToList(); return(items); } }
public IEnumerable <Staff> GetStaffList(StaffRequest request = null) { request = request ?? new StaffRequest(); using (var dbContext = new HRDbContext()) { IQueryable <Staff> staffs = dbContext.Staffs.Include("Branch"); if (!string.IsNullOrEmpty(request.Name)) { staffs = staffs.Where(u => u.Name.Contains(request.Name)); } if (request.BranchId > 0) { staffs = staffs.Where(u => u.BranchId == request.BranchId); } return(staffs.OrderByDescending(u => u.ID).ToPagedList(request.PageIndex, request.PageSize)); } }
public SelectItem GetOfficeArea(Guid?areaId) { if (areaId == null || areaId == Guid.Empty) { return(new SelectItem()); } var tenantId = this.GetCurrentCredential().TenantGuid(); using (var dc = new HRDbContext()) { var query = dc.HR_EMP_OfficeArea.Where(c => c.TenantID == tenantId && c.AreaID == areaId.Value); var item = query.FirstOrDefault(); if (item == null) { return(new SelectItem()); } return(new SelectItem { ID = item.AreaID.ToString(), Name = item.AreaName, Code = item.AreaCode }); } }
public BusinessResult GetEmployeeList(BusinessContext context) { using (var db = new HRDbContext()) { var tenantId = this.GetCurrentCredential().TenantGuid(); var query = from c in db.HR_EMP_Employee.Where(c => c.TenantID == tenantId && !c.IsDeleted) join l in db.HR_ORG_LegalEntity.Where(p => !p.IsDeleted) on c.LegalEntityID equals l.LegalEntityID join area in db.HR_EMP_OfficeArea on c.OfficeAreaID equals area.AreaID into atemp from area in atemp.DefaultIfEmpty() select new { EmployeeId = c.EmployeeID, EmployeeName = c.EmployeeNameCN, EmployeeNo = c.EmployeeNumber, ExtCode = c.ExtCode, TeleCode = c.TeleCode, OfficeAreaID = c.OfficeAreaID, OfficeAreaName = area.AreaName, EMail = c.EmployeeEMail, Mobile = c.PersonalCellPhone, LegalID = c.LegalEntityID, LegalEntityName = l.LegalEntityName, MainJobPositionID = c.MainJobPositionID, MainJobPostionName = c.MainJobPostionName, OrganizationID = c.OrganizationID, OrganizationCode = c.OrganizationCode, OrganizationName = c.OrganizationName, OnboardDate = c.OnboardDate, TrialBeginDate = c.TrialBeginDate, TrialEndDate = c.TrialEndDate, PersonalCellPhone = c.PersonalCellPhone, PhotoAttachmentID = c.PhotoAttachmentID, CreateTime = c.CreateTime, imageUrl = "" }; var total = 0; query = BizHelper.GetPageQuery(context, query.OrderBy(g => g.CreateTime), out total); return(this.Success(new { total = total, rows = query.ToArray() })); } }
public BusinessResult GetOfficeAreaData(BusinessContext context)//不考虑法人 { //var legalId = context.Credential.LegalGuid(); //var tenantId = context.Credential.TenantGuid(); var areaname = context.Request["areaname"]; var areacode = context.Request["areacode"]; using (var dbContect = new HRDbContext()) { var query = from area in dbContect.HR_EMP_OfficeArea where area.IsDeleted == false && area.IsUse == true /*.TenantID == tenantId && area.LegalEntityID == legalId*/ select new { area.AreaID, area.AreaCode, area.AreaName, area.DetailAddress, area.CreateTime }; if (!string.IsNullOrEmpty(areaname)) { query = query.Where(u => u.AreaName.Contains(areaname)); } if (!string.IsNullOrEmpty(areacode)) { query = query.Where(u => u.AreaCode.Contains(areacode)); } int total = 0; query = BizHelper.GetPageQuery(context, query.OrderBy(g => g.CreateTime), out total); return(this.OK(new { total = total, rows = query.ToArray() })); //return this.OK(new { total = total, rows = new List<dynamic> { new { // EmployeeID = "B31E66F4-2E66-4C55-8957-1A50280F9696", // EmployeeNameCN = "赵六", // EmployeeNumber = "123", // IsMain = false //} } }); } }
public void UpdateUserRoleByPositonID(Guid positionID) { var permissionService = GetBizService <IBizPermissionService>(); using (var db = new HRDbContext()) { var posId = positionID.ToString(); var tenantId = this.GetCurrentCredential().TenantGuid(); var uIDs = db.SYS_User.Where(t => t.BelongOrg.Contains(posId) && t.UserType == this.EmployeeUserType && t.TenantId == tenantId).Select(a => a.UserId.ToString()).ToList(); var posRoleList = db.HR_ORG_PositionRoleList.Where(pr => pr.PositionID == positionID).Select(pr => pr.RoleID.ToString()).ToArray(); if (uIDs != null && uIDs.Count() > 0) { foreach (var uID in uIDs) { var user = permissionService.GetUser(uID, this.EmployeeUserType); if (user != null) { user.RoleList.AddRange(posRoleList); permissionService.SaveUser(user); } } } } }
public List <EmployeeInfo> GetEmployeeInfos(Guid[] ids, DictTable queryParam = null) { using (var db = new HRDbContext()) { var tenantId = this.GetCurrentCredential().TenantGuid(); var query = from c in db.HR_EMP_Employee.Where(c => c.TenantID == tenantId && !c.IsDeleted) join l in db.HR_ORG_LegalEntity.Where(p => !p.IsDeleted) on c.LegalEntityID equals l.LegalEntityID join area in db.HR_EMP_OfficeArea on c.OfficeAreaID equals area.AreaID into atemp from area in atemp.DefaultIfEmpty() where ids.Contains(c.EmployeeID) select new EmployeeInfo() { EmployeeId = c.EmployeeID, EmployeeName = c.EmployeeNameCN, EmployeeNo = c.EmployeeNumber, ExtCode = c.ExtCode, TeleCode = c.TeleCode, OfficeAreaID = c.OfficeAreaID, OfficeAreaName = area.AreaName, EMail = c.EmployeeEMail, Mobile = c.PersonalCellPhone, LegalID = c.LegalEntityID, LegalEntityName = l.LegalEntityName, MainJobPositionID = c.MainJobPositionID, MainJobPostionName = c.MainJobPostionName, OrganizationID = c.OrganizationID, OrganizationCode = c.OrganizationCode, OrganizationName = c.OrganizationName, OnboardDate = c.OnboardDate, TrialBeginDate = c.TrialBeginDate, TrialEndDate = c.TrialEndDate, PersonalCellPhone = c.PersonalCellPhone, }; return(query.ToList()); } }
public PersonelsController(HRDbContext context) { _context = context; }
public static async Task InvokeAsync(IServiceScope scope, HRDbContext db) { if (!db.Warehouses.Any()) { await db.Warehouses.AddRangeAsync(new Warehouse { Name = "NewYorker", Address = "." }, new Warehouse { Name = "Celio", Address = "." }, new Warehouse { Name = "Emporium", Address = "." }, new Warehouse { Name = "Mango", Address = "." } ); await db.SaveChangesAsync(); } var roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); if (!roleManager.Roles.Any()) { string[] roles = { "Admin", "HR", "PayrollSpecialist", "DepartmentHead" }; foreach (var role in roles) { await roleManager.CreateAsync(new IdentityRole { Name = role }); } } var configuration = scope.ServiceProvider.GetRequiredService <IConfiguration>(); if (!db.Users.Any()) { var userManager = scope.ServiceProvider.GetRequiredService <UserManager <User> >(); User admin = new User { Name = "Admin", Surname = "Admin", UserName = "******", Email = "*****@*****.**", }; var adminCreateResult = await userManager.CreateAsync(admin, configuration["Admin:Password"]); if (adminCreateResult.Succeeded) { await userManager.AddToRoleAsync(admin, "Admin"); } } }
public PublicHolidaysController(HRDbContext context) { _context = context; }
public EmployeesController() { string connectionString = @"Server=WGHOSH6\SQL2017;Database=HRDb;User Id=blah;Password=blah;"; dbContext = HRDbContextFactory.Create(connectionString); }
public DefaultLanguagesCreator(HRDbContext context) { _context = context; }
public OffDaysController(HRDbContext context) { _context = context; }
public DefaultSettingsCreator(HRDbContext context) { _context = context; }