//Burdan sonrası Ezgi'nin public IActionResult GetUserForCompany(int companyId) { var agentList = applicationUserService.GetAllUser(); var mapping = companyAgentMappingService.GetMappingsByCompanyId(companyId); var joinedData = mapping.Join(agentList, e1 => e1.ApplicationUserId, e2 => e2.Id, (e1, e2) => e2).Distinct(); return(Content(JsonConvert.SerializeObject(joinedData), "application/json")); }
public ContentResult GetAllIncomingDemands(int?orderType, string filterType) { var user = httpContextAccessor.HttpContext.User; IEnumerable <Claim> claims = user.Claims; var userIdentityId = httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); var account = userManager.FindByIdAsync(userIdentityId).Result; var roles = userManager.GetRolesAsync(account).Result; var applicationUserId = applicationUserService.GetAllUser().Where(p => p.AccountId == account.AccountId).Select(p => p.Id).FirstOrDefault(); //Belirtilen filtredeki tüm talepler var incomingDemands = demandService.GetAll(filterType, roles.ToList(), account.AccountId); if (!roles.Contains("Admin")) { //User'a ait tüm mappingler var mapping = companyAgentMappingService.GetMappingsByUserId(applicationUserId); //Özelleştirme koşularını sağlayan nihai talepler List <Demand> demands = new List <Demand>(); //En az bir özelliştirme yapılan firmaların id'leri List <int> idsForCustomizedCompany = new List <int>(); //Hiç özelliştirme yapılmayan firmaların id'leri List <int> idsForNoncustomizedCompany = new List <int>(); foreach (var companyId in mapping.Select(p => p.CompanyId)) { var mapCompanyIds = companyAgentMappingService.GetMappingsByCompanyId(companyId); if (mapCompanyIds.Where(p => p.IsSpecifiedForCompany).Select(q => q.CompanyId).ToList().Count > 0) { idsForCustomizedCompany.AddRange(mapCompanyIds.Where(p => p.IsSpecifiedForCompany).Select(q => q.CompanyId).ToList()); } else { idsForNoncustomizedCompany.AddRange(mapCompanyIds.Select(q => q.CompanyId).ToList()); } } if (idsForCustomizedCompany.Count > 0) { //Kullanıcının o firmada özelleştirilen bir mappingi var mı? var maps = mapping.Where(p => idsForCustomizedCompany.Contains(p.CompanyId) && p.ApplicationUserId == applicationUserId && p.IsSpecifiedForCompany); var demandsNew = incomingDemands.Where(p => maps.Select(q => q.CompanyId).Contains(p.CompanyId)).ToList(); demands.AddRange(demandsNew); } if (idsForNoncustomizedCompany.Count > 0) { var maps = mapping.Where(p => idsForNoncustomizedCompany.Contains(p.CompanyId)); var demandsNew = incomingDemands.Where(p => maps.Select(q => q.CompanyId).Contains(p.CompanyId)).ToList(); demands.AddRange(demandsNew); } incomingDemands = demands; } if (orderType != null) { if (orderType == 1) { incomingDemands = incomingDemands.OrderBy(p => p.OrderOfUrgencyId); } else if (orderType == 2) { incomingDemands = incomingDemands.OrderByDescending(p => p.OrderOfUrgencyId); } else if (orderType == 3) { incomingDemands = incomingDemands.OrderBy(p => p.CreateDate); } else if (orderType == 4) { incomingDemands = incomingDemands.OrderByDescending(p => p.CreateDate); } } return(Content(JsonConvert.SerializeObject(incomingDemands), "application/json")); }