From 13de0988f00c8f2e3e6fc45b35bcf7a89816e646 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 6 Oct 2021 15:12:05 +0000 Subject: [PATCH] --- .../AyaNova/Controllers/ScheduleController.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/server/AyaNova/Controllers/ScheduleController.cs b/server/AyaNova/Controllers/ScheduleController.cs index 96f1501d..47006e28 100644 --- a/server/AyaNova/Controllers/ScheduleController.cs +++ b/server/AyaNova/Controllers/ScheduleController.cs @@ -93,33 +93,37 @@ namespace AyaNova.Api.Controllers //Tags to Users - List Users = null; + List Users = null; if (p.Tags.Count == 0) - Users = await ct.User.AsNoTracking().Where(x => x.Active == true && x.UserType == UserType.ServiceContractor || x.UserType == UserType.Service).OrderBy(x => x.Name).Select(x => x.Id).ToListAsync(); + Users = await ct.User.AsNoTracking() + .Where(x => x.Active == true && x.UserType == UserType.ServiceContractor || x.UserType == UserType.Service) + .OrderBy(x => x.Name) + .Select(x => new NameIdItem { Name = x.Name, Id = x.Id }) + .ToListAsync(); else { - Users = new List(); + Users = new List(); //add users that match any of the tags, to match they must have at least one of the tags //iterate available users - var availableUsers = await ct.User.AsNoTracking().Where(x => x.Active == true && x.UserType == UserType.ServiceContractor || x.UserType == UserType.Service).OrderBy(x => x.Name).Select(x => new { x.Id, x.Tags }).ToListAsync(); + var availableUsers = await ct.User.AsNoTracking().Where(x => x.Active == true && x.UserType == UserType.ServiceContractor || x.UserType == UserType.Service).OrderBy(x => x.Name).Select(x => new { x.Name, x.Id, x.Tags }).ToListAsync(); //if user has any of the tags in the list then include them foreach (var u in availableUsers) { //any of the inclusive tags in contact tags? if (p.Tags.Intersect(u.Tags).Any()) - Users.Add(u.Id); - } - + Users.Add(new NameIdItem { Name = u.Name, Id = u.Id }); + } } + List userIdList = Users.Select(x => x.Id).ToList(); //WORKORDERS { //Note: query for *overlapping* ranges, not *contained* entirely in view range - r.AddRange(await ct.ViewScheduleWorkOrder.Where(x => Users.Contains(x.SchedUserId) && ViewStart <= x.StopDate && x.StartDate <= ViewEnd) + r.AddRange(await ct.ViewScheduleWorkOrder.Where(x => userIdList.Contains(x.SchedUserId) && ViewStart <= x.StopDate && x.StartDate <= ViewEnd) .Select(x => MakeServiceWOSchedItem(x, p)) .ToListAsync()); } - return Ok(ApiOkResponse.Response(r)); + return Ok(ApiOkResponse.Response(new { items = r, users = Users })); } public class ServiceScheduleParams