This commit is contained in:
@@ -93,33 +93,37 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
//Tags to Users
|
//Tags to Users
|
||||||
List<long> Users = null;
|
List<NameIdItem> Users = null;
|
||||||
|
|
||||||
if (p.Tags.Count == 0)
|
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
|
else
|
||||||
{
|
{
|
||||||
Users = new List<long>();
|
Users = new List<NameIdItem>();
|
||||||
//add users that match any of the tags, to match they must have at least one of the tags
|
//add users that match any of the tags, to match they must have at least one of the tags
|
||||||
//iterate available users
|
//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
|
//if user has any of the tags in the list then include them
|
||||||
foreach (var u in availableUsers)
|
foreach (var u in availableUsers)
|
||||||
{
|
{
|
||||||
//any of the inclusive tags in contact tags?
|
//any of the inclusive tags in contact tags?
|
||||||
if (p.Tags.Intersect(u.Tags).Any())
|
if (p.Tags.Intersect(u.Tags).Any())
|
||||||
Users.Add(u.Id);
|
Users.Add(new NameIdItem { Name = u.Name, Id = u.Id });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
List<long> userIdList = Users.Select(x => x.Id).ToList();
|
||||||
//WORKORDERS
|
//WORKORDERS
|
||||||
{
|
{
|
||||||
//Note: query for *overlapping* ranges, not *contained* entirely in view range
|
//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))
|
.Select(x => MakeServiceWOSchedItem(x, p))
|
||||||
.ToListAsync());
|
.ToListAsync());
|
||||||
}
|
}
|
||||||
return Ok(ApiOkResponse.Response(r));
|
return Ok(ApiOkResponse.Response(new { items = r, users = Users }));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ServiceScheduleParams
|
public class ServiceScheduleParams
|
||||||
|
|||||||
Reference in New Issue
Block a user