public HttpResponseMessage GetDepOfParentCompanies(GetParentListDTO obj) { try { var Departments = _departmentServices.GetDepOfParentCompanies(obj); return(Request.CreateResponse(HttpStatusCode.OK, Departments)); } catch (Exception ex) { throw new ApiDataException(1000, "Departments not found", HttpStatusCode.NotFound); } }
public IEnumerable <UserCompanyDTO> GetParentCompByCompId(GetParentListDTO obj) { var allCompanies = _unitOfWork.CompanyRepository.GetAll().Where(c => c.IsActive == true); var resCompanies = new List <Company>(); resCompanies.Add(allCompanies.First(c => c.CompanyId == obj.CompanyId)); resCompanies.AddRange(CommonService.getParentsList(allCompanies, resCompanies.First().ParentCompany, obj.UserCompanyId)); resCompanies.Reverse(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <Company, UserCompanyDTO>(); }); IMapper mapper = config.CreateMapper(); var result = mapper.Map <List <Company>, List <UserCompanyDTO> >(resCompanies); return(result); }
public IEnumerable <DepartmentEntity> GetDepOfParentCompanies(GetParentListDTO obj) { var allCompanies = _unitOfWork.CompanyRepository.GetAll().Where(c => c.IsActive == true); var resCompanies = new List <Company>(); resCompanies.Add(allCompanies.First(c => c.CompanyId == obj.CompanyId)); resCompanies.AddRange(CommonService.getParentsList(allCompanies, resCompanies.First().ParentCompany, obj.UserCompanyId)); var compIdLsit = from company in resCompanies select(company.CompanyId); var allDepartments = _unitOfWork.DepartmentRepository.GetAll(); var departments = allDepartments.Where(d => compIdLsit.Contains(d.CompanyId)).ToList(); if (departments.Any()) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <Company, DepartmentCompanyDTO>(); cfg.CreateMap <Department, DepartmentEntity>(); }); IMapper mapper = config.CreateMapper(); var departmentList = mapper.Map <List <Department>, List <DepartmentEntity> >(departments); foreach (var d in departmentList) { if (d.ParentId > 0) { d.ParentName = allDepartments.Where(dep => dep.DepartmentId == d.ParentId).First().DepartmentName; } else { d.ParentName = String.Empty; } } return(departmentList); } return(null); }