예제 #1
0
        public HttpResponseMessage GetEmployees(long id, [FromUri]long[] loc = null)
        {
            if (id <= 0)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            IEnumerable<Employee> output = null;
            IEnumerable<EmployeeModel> employees = null;
            if (!loc.IsNullOrEmpty())
            {
                JoinTableRepository<EmployeeModel, SkillsetModel> repository = new JoinTableRepository<EmployeeModel, SkillsetModel>();
                IEnumerable<string> employeeIds = repository.GetLeft(id).Select(x => x.EmpId).ToList();
                CommonRepository<MToMTableModel<EmployeeModel, LocationModel>> repositoryEmpLoc = new CommonRepository<MToMTableModel<EmployeeModel, LocationModel>>();
                employees = repositoryEmpLoc.GetBySpecification(new Specification<MToMTableModel<EmployeeModel, LocationModel>>(x => x.LeftItem.IsActive == true && x.RightItem.IsActive == true && employeeIds.Contains(x.LeftItem.EmpId) && loc.Contains(x.RightItem.Id))).Select(x => x.LeftItem);
                output = AutoMapper.MapCollection<EmployeeModel, Employee>(employees);
            }
            else
            {
                TryGetItemEmployees(id, out output);
            }

            if (output.IsNullOrEmpty())
            {
                return Request.CreateResponse(HttpStatusCode.NotFound);
            }

            Response<IEnumerable<Employee>> results = new Response<IEnumerable<Employee>>(output);
            return Request.CreateResponse(HttpStatusCode.OK, results);
        }
예제 #2
0
        public HttpResponseMessage GetLocations(long id, [FromUri]string groupBy)
        {
            if (id <= 0)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            if (string.IsNullOrEmpty(groupBy) || !string.Equals(groupBy, "emp", StringComparison.OrdinalIgnoreCase))
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            List<Location> locations = null;
            JoinTableRepository<EmployeeModel, SkillsetModel> repository = new JoinTableRepository<EmployeeModel, SkillsetModel>();
            IEnumerable<EmployeeModel> employees = repository.GetLeft(id);
            IEnumerable<string> employeeIds = employees.Select(x => x.EmpId);
            if (!employeeIds.IsNullOrEmpty())
            {
                CommonRepository<MToMTableModel<EmployeeModel, LocationModel>> repositoryEmpLoc = new CommonRepository<MToMTableModel<EmployeeModel, LocationModel>>();
                var op = repositoryEmpLoc.GetBySpecification(new Specification<MToMTableModel<EmployeeModel, LocationModel>>(x => x.LeftItem.IsActive == true && x.RightItem.IsActive == true && employeeIds.Contains(x.LeftItem.EmpId)));
                var tbl = from t1 in op
                          group t1 by t1.RightItem into newGroup
                          select new { Loc = newGroup.Key, EmpCount = newGroup.Count() };
                locations = new List<Location>();
                foreach (var item in tbl)
                {
                    Location loc = AutoMapper.Map<LocationModel, Location>(item.Loc);
                    loc.ExtendedProperties = new Dictionary<string, string>()
                    {
                        { "emp-count", item.EmpCount.ToString()} // string.Join(",", item.Select(x => x.LeftItem.EmpId)) }
                    };

                    locations.Add(loc);
                }
            }

            IEnumerable<Location> target = locations; // AutoMapper.MapCollection<LocationModel, Location>(locations);
            if (target.IsNullOrEmpty())
            {
                return Request.CreateResponse(HttpStatusCode.NotFound);
            }

            Response<IEnumerable<Location>> results = new Response<IEnumerable<Location>>(target);
            return Request.CreateResponse(HttpStatusCode.OK, results);
        }
예제 #3
0
        private bool TryGetItemEmployees(long id, out IEnumerable<Employee> results)
        {
            string cacheKey = "aditi:gis:arm:data:stream-" + id.ToString() + "-employee";
            if (!cache.TryGet(cacheKey, out results))
            {
                JoinTableRepository<EmployeeModel, StreamModel> repository = new JoinTableRepository<EmployeeModel, StreamModel>();
                IEnumerable<EmployeeModel> employees = repository.GetLeft(id);
                results = AutoMapper.MapCollection<EmployeeModel, Employee>(employees);
                if (results.IsNullOrEmpty())
                {
                    results = null;
                    return false;
                }

                cache.Set(cacheKey, results, InMemoryCache.OneDay);
            }

            return true;
        }
예제 #4
0
        public HttpResponseMessage GetEmployeeBySkills(long id, [FromUri]long[] skill = null, [FromUri] string flag = "none")
        {
            if (id <= 0)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            List<EmployeeLite> result = null;
            result = new List<EmployeeLite>();
            JoinTableRepository<EmployeeModel, LocationModel> repository = new JoinTableRepository<EmployeeModel, LocationModel>();
            IEnumerable<string> employeeIds = repository.GetLeft(id).Select(x => x.EmpId).ToList();
            CommonRepository<MToMTableModel<EmployeeModel, SkillsetModel>> repositoryEmpSkills = new CommonRepository<MToMTableModel<EmployeeModel, SkillsetModel>>();
            CommonRepository<MToMVersionableTableModel<EmployeeModel, ProjectModel>> repositoryEmpProjects = new CommonRepository<MToMVersionableTableModel<EmployeeModel, ProjectModel>>();
            if (skill.IsNullOrEmpty())
            {
                skill = repositoryEmpSkills.GetBySpecification(new Specification<MToMTableModel<EmployeeModel, SkillsetModel>>(x => x.LeftItem.IsActive == true && x.RightItem.IsActive == true && employeeIds.Contains(x.LeftItem.EmpId))).Select(x => x.RightItem.Id).Distinct().ToArray();
            }

            if (skill.IsNullOrEmpty())
            {
                return Request.CreateResponse(HttpStatusCode.NotFound);
            }

            foreach (long skillsetId in skill.Distinct())
            {
                IEnumerable<EmployeeModel> skillEmps = repositoryEmpSkills.GetBySpecification(new Specification<MToMTableModel<EmployeeModel, SkillsetModel>>(x => x.LeftItem.IsActive == true && x.RightItem.IsActive == true && employeeIds.Contains(x.LeftItem.EmpId) && skillsetId == x.RightItem.Id)).Select(x => x.LeftItem).ToList();
                if (!skillEmps.IsNullOrEmpty())
                {
                    switch (flag)
                    {
                        case "billed":
                            employeeIds = skillEmps.Select(x => x.EmpId).ToList();
                            var skillProjEmps = repositoryEmpProjects.GetBySpecification(new Specification<MToMVersionableTableModel<EmployeeModel, ProjectModel>>(x => x.LeftItem.IsActive == true
                                                   && x.RightItem.IsActive == true && employeeIds.Contains(x.LeftItem.EmpId))).Select(x => x.LeftItem).ToList();
                            // total skilled employees billable
                            result = ConstructEmployeeLiteList(skillProjEmps);
                            break;
                        case "unbilled":
                            employeeIds = skillEmps.Select(x => x.EmpId).ToList();
                            var skillProjEmpIds = repositoryEmpProjects.GetBySpecification(new Specification<MToMVersionableTableModel<EmployeeModel, ProjectModel>>(x => x.LeftItem.IsActive == true
                                                   && x.RightItem.IsActive == true && employeeIds.Contains(x.LeftItem.EmpId))).Select(x => x.LeftItem.EmpId).ToList();
                            var skillNonProjEmps = skillEmps.Where(x => !skillProjEmpIds.Contains(x.EmpId)).ToList();
                            // total skilled employees non billable
                            result = ConstructEmployeeLiteList(skillNonProjEmps);
                            break;
                        default:
                            // total skilled employees in location
                            result = ConstructEmployeeLiteList(skillEmps);
                            break;
                    }
                }
            }

            if (result.IsNullOrEmpty())
            {
                return Request.CreateResponse(HttpStatusCode.NotFound);
            }

            Response<List<EmployeeLite>> results = new Response<List<EmployeeLite>>(result);
            return Request.CreateResponse(HttpStatusCode.OK, results);
        }
예제 #5
0
        public HttpResponseMessage GetEmployeeUtilization(long id, [FromUri]long[] skill = null)
        {
            if (id <= 0)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            CustomData result = null;
            result = new CustomData();
            JoinTableRepository<EmployeeModel, LocationModel> repository = new JoinTableRepository<EmployeeModel, LocationModel>();
            IEnumerable<string> employeeIds = repository.GetLeft(id).Select(x => x.EmpId).ToList();
            CommonRepository<MToMTableModel<EmployeeModel, SkillsetModel>> repositoryEmpSkills = new CommonRepository<MToMTableModel<EmployeeModel, SkillsetModel>>();
            CommonRepository<MToMVersionableTableModel<EmployeeModel, ProjectModel>> repositoryEmpProjects = new CommonRepository<MToMVersionableTableModel<EmployeeModel, ProjectModel>>();
            if (skill.IsNullOrEmpty())
            {
                skill = repositoryEmpSkills.GetBySpecification(new Specification<MToMTableModel<EmployeeModel, SkillsetModel>>(x => x.LeftItem.IsActive == true && x.RightItem.IsActive == true && employeeIds.Contains(x.LeftItem.EmpId))).Select(x => x.RightItem.Id).Distinct().ToArray();
            }

            if (skill.IsNullOrEmpty())
            {
                return Request.CreateResponse(HttpStatusCode.NotFound);
            }

            foreach (long skillsetId in skill.Distinct())
            {
                // total skilled employees in location
                var skillEmpIds = repositoryEmpSkills.GetBySpecification(new Specification<MToMTableModel<EmployeeModel, SkillsetModel>>(x => x.LeftItem.IsActive == true && x.RightItem.IsActive == true && employeeIds.Contains(x.LeftItem.EmpId) && skillsetId == x.RightItem.Id)).Select(x => x.LeftItem.EmpId).ToList();
                int locSkillEmpCount = skillEmpIds.Count();
                if (locSkillEmpCount > 0)
                {
                    var skillProjEmpCount = repositoryEmpProjects.GetBySpecification(new Specification<MToMVersionableTableModel<EmployeeModel, ProjectModel>>(x => x.LeftItem.IsActive == true
                        && x.RightItem.IsActive == true && skillEmpIds.Contains(x.LeftItem.EmpId))).Count();
                    result.ExtendedProperties[skillsetId.ToString()] = locSkillEmpCount.ToString() + "," + skillProjEmpCount.ToString();
                }
                else
                {
                    result.ExtendedProperties[skillsetId.ToString()] = locSkillEmpCount.ToString() + "," + 0.ToString();
                }
            }

            Response<CustomData> results = new Response<CustomData>(result);
            return Request.CreateResponse(HttpStatusCode.OK, results);
        }