public PagedCompaniesDto GetAllByUser(int userId, int page, int pageSize, string companyName) { var repoUser = _contextManager.CreateRepositiry <IUserRepo>(); var user = repoUser.GetById(userId); var repoUserCompanies = _contextManager.CreateRepositiry <ICompanyUserLinkRepo>(); var listUserCompanies = repoUserCompanies.GetCompaniesByUser(user.Id, page, pageSize, companyName); var companyListDto = _mapper.Map <List <CompanyDto> >(listUserCompanies); var companyIdList = companyListDto.Select(c => c.Id).ToList(); var companyLinks = repoUserCompanies.GetCompanyUserLinkListForUser(userId, companyIdList); foreach (var oneCompany in companyListDto) { var thisCompanyLink = companyLinks.Where(c => c.CompanyId == oneCompany.Id).FirstOrDefault(); if (thisCompanyLink != null) { oneCompany.UserRole = thisCompanyLink.UserCompanyRole; } } var retDto = new PagedCompaniesDto() { Companies = companyListDto, Paging = new PagingDto() { CurrentPage = page, PageSize = pageSize, TotalItems = repoUserCompanies.GetCompaniesByUserCount(user.Id) } }; return(retDto); }
public PagedCompaniesDto GetAllByOwner(int userId, int page, int pageSize, string companyName) { var repo = _contextManager.CreateRepositiry <ICompanyRepo>(); var repoUser = _contextManager.CreateRepositiry <IUserRepo>(); var user = repoUser.GetById(userId); if (user == null) { throw new ValidationException("User not found"); } var comp = repo.GetAllCompaniesByOwner(user.Id, page, pageSize, companyName); var companyListDto = _mapper.Map <List <CompanyDto> >(comp); foreach (var oneCompany in companyListDto) { oneCompany.UserRole = (int)Model.Enums.CompanyUserRoleEnum.Owner; } var retDto = new PagedCompaniesDto() { Companies = companyListDto, Paging = new PagingDto() { CurrentPage = page, PageSize = pageSize, TotalItems = repo.GetAllCompaniesByOwnerCount(user.Id) } }; return(retDto); }