public IEnumerable <StatusRequestDTO> GetListSubscribeStatus(long userId) { IEnumerable <RawStatusRequestDTO> list = statusRepository.GetList(t => !RequestService.IgnoredRawRequestStates.Contains(t.Id)) .OrderBy(s => s.Name) .Select(s => new RawStatusRequestDTO { Id = s.Id, Name = s.Name }) .ToList(); IEnumerable <CabinetUserEventSubscribe> listSubscribe = userEventSubscribeRepository.GetList(e => e.User.Id == userId).ToList(); var q = (from s in list join ss in listSubscribe on s.Id equals ss.StatusRequest.Id into jss from ss in jss.DefaultIfEmpty() select new { s, Checked = (ss != null) }) .ToList() .Select(t => new StatusRequestDTO { Id = statusRequestMapService.GetEquivalenceByElement(t.s.Id), Name = statusRequestMapService.GetEquivalenceByElement(t.s.Id).GetDisplayName(), Checked = t.Checked }); return(q.Distinct()); }
private IEnumerable <RequestDTO> getList(GetListRequestDelegate getListActive, GetListRequestDelegate getListArchive, RequestFilter filter, OrderInfo orderInfo, PageInfo pageInfo) { IEnumerable <RequestDTO> list = null; if (filter.Ids != null && filter.Ids.Any()) { PageInfo pageInfoActive = new PageInfo() { CurrentPage = 0, PageSize = int.MaxValue }; PageInfo pageInfoArchive = new PageInfo() { CurrentPage = 0, PageSize = int.MaxValue }; IEnumerable <RequestDTO> listActive = getListActive(pageInfoActive); IEnumerable <RequestDTO> listArchive = getListArchive(pageInfoArchive); foreach (RequestDTO r in listArchive) { r.Archive = true; } pageInfo.Count = pageInfoActive.Count + pageInfoArchive.Count; pageInfo.TotalCount = pageInfoActive.TotalCount + pageInfoArchive.TotalCount; list = listActive.Union(listArchive); } else if (filter.Archive) { list = getListArchive(pageInfo); foreach (RequestDTO r in list) { r.Archive = true; } } else { list = getListActive(pageInfo); } IEnumerable <long> requestIds = list.Select(r => r.Id).ToList(); #region files IEnumerable <RequestFileInfoDTO> files = requestFileRepository.GetList(t => t.RequestId != null && requestIds.Contains(t.RequestId.Value)) .Select(t => new RequestFileInfoDTO() { Id = t.Id, ForignKeyId = t.RequestId, Name = t.Name, Size = t.Size, TempRequestKey = t.TempRequestKey, Type = t.Type }); IDictionary <long, IList <RequestFileInfoDTO> > fileIndex = new Dictionary <long, IList <RequestFileInfoDTO> >(); foreach (RequestFileInfoDTO r in files) { if (fileIndex.ContainsKey(r.ForignKeyId.Value)) { fileIndex[r.ForignKeyId.Value].Add(r); } else { fileIndex[r.ForignKeyId.Value] = new List <RequestFileInfoDTO>() { r } }; } #endregion files #region LastEvent //IEnumerable<RequestEventDTO> events = queryHandler.Run(new RequestLastEventQuery(requestIds)); var events = queryHandler.Handle <RequestLastEventQueryParam, IEnumerable <RequestEventDTO>, IQuery <RequestLastEventQueryParam, IEnumerable <RequestEventDTO> > > (new RequestLastEventQueryParam { RequestIds = requestIds }, _requestLastEventQuery); IDictionary <long, RequestEventDTO> eventIndex = new Dictionary <long, RequestEventDTO>(); foreach (RequestEventDTO e in events) { eventIndex[e.RequestId] = e; } #endregion LastEvent foreach (RequestDTO r in list) { r.Files = fileIndex.ContainsKey(r.Id) ? fileIndex[r.Id] : null; r.LastEvent = eventIndex.ContainsKey(r.Id) ? eventIndex[r.Id] : null; r.StatusRequest = statusRequestMapService.GetEquivalenceByElement(r.Status.Id); } return(list); }