public void Delete(TimeCardSearch request) { var matches = Get(request) as List <TimeCard>; if (true != matches?.Any()) { throw new HttpError(HttpStatusCode.NotFound, "No matches for request"); } matches.ForEach(match => { Delete(match); }); }
public object Get(TimeCardSearch request) => GetSearchResultWithCache <TimeCard, DocEntityTimeCard, TimeCardSearch>(DocConstantModelName.TIMECARD, request, _ExecSearch);
private IQueryable <DocEntityTimeCard> _ExecSearch(TimeCardSearch request, DocQuery query) { request = InitSearch <TimeCard, TimeCardSearch>(request); IQueryable <DocEntityTimeCard> entities = null; query.Run(session => { entities = query.SelectAll <DocEntityTimeCard>(); if (!DocTools.IsNullOrEmpty(request.FullTextSearch)) { var fts = new TimeCardFullTextSearch(request); entities = GetFullTextSearch <DocEntityTimeCard, TimeCardFullTextSearch>(fts, entities); } if (null != request.Ids && request.Ids.Any()) { entities = entities.Where(en => en.Id.In(request.Ids)); } if (!DocTools.IsNullOrEmpty(request.Updated)) { entities = entities.Where(e => null != e.Updated && e.Updated.Value.Date == request.Updated.Value.Date); } if (!DocTools.IsNullOrEmpty(request.UpdatedBefore)) { entities = entities.Where(e => null != e.Updated && e.Updated <= request.UpdatedBefore); } if (!DocTools.IsNullOrEmpty(request.UpdatedAfter)) { entities = entities.Where(e => null != e.Updated && e.Updated >= request.UpdatedAfter); } if (!DocTools.IsNullOrEmpty(request.Created)) { entities = entities.Where(e => null != e.Created && e.Created.Value.Date == request.Created.Value.Date); } if (!DocTools.IsNullOrEmpty(request.CreatedBefore)) { entities = entities.Where(e => null != e.Created && e.Created <= request.CreatedBefore); } if (!DocTools.IsNullOrEmpty(request.CreatedAfter)) { entities = entities.Where(e => null != e.Created && e.Created >= request.CreatedAfter); } if (true == request.Archived?.Any() && currentUser.HasProperty(DocConstantModelName.TIMECARD, nameof(Reference.Archived), DocConstantPermission.VIEW)) { entities = entities.Where(en => en.Archived.In(request.Archived)); } else { entities = entities.Where(en => !en.Archived); } if (true == request.Locked?.Any()) { entities = entities.Where(en => en.Locked.In(request.Locked)); } if (!DocTools.IsNullOrEmpty(request.Description)) { entities = entities.Where(en => en.Description.Contains(request.Description)); } if (!DocTools.IsNullOrEmpty(request.Descriptions)) { entities = entities.Where(en => en.Description.In(request.Descriptions)); } if (!DocTools.IsNullOrEmpty(request.Document) && !DocTools.IsNullOrEmpty(request.Document.Id)) { entities = entities.Where(en => en.Document.Id == request.Document.Id); } if (true == request.DocumentIds?.Any()) { entities = entities.Where(en => en.Document.Id.In(request.DocumentIds)); } if (!DocTools.IsNullOrEmpty(request.End)) { entities = entities.Where(en => request.End.Value.Date == en.End.Date); } if (!DocTools.IsNullOrEmpty(request.EndBefore)) { entities = entities.Where(en => en.End <= request.EndBefore); } if (!DocTools.IsNullOrEmpty(request.EndAfter)) { entities = entities.Where(en => en.End >= request.EndAfter); } if (!DocTools.IsNullOrEmpty(request.Project) && !DocTools.IsNullOrEmpty(request.Project.Id)) { entities = entities.Where(en => en.Project.Id == request.Project.Id); } if (true == request.ProjectIds?.Any()) { entities = entities.Where(en => en.Project.Id.In(request.ProjectIds)); } if (request.ReferenceId.HasValue) { entities = entities.Where(en => request.ReferenceId.Value == en.ReferenceId); } if (!DocTools.IsNullOrEmpty(request.Start)) { entities = entities.Where(en => request.Start.Value.Date == en.Start.Date); } if (!DocTools.IsNullOrEmpty(request.StartBefore)) { entities = entities.Where(en => en.Start <= request.StartBefore); } if (!DocTools.IsNullOrEmpty(request.StartAfter)) { entities = entities.Where(en => en.Start >= request.StartAfter); } if (!DocTools.IsNullOrEmpty(request.Status) && !DocTools.IsNullOrEmpty(request.Status.Id)) { entities = entities.Where(en => en.Status.Id == request.Status.Id); } if (true == request.StatusIds?.Any()) { entities = entities.Where(en => en.Status.Id.In(request.StatusIds)); } else if (!DocTools.IsNullOrEmpty(request.Status) && !DocTools.IsNullOrEmpty(request.Status.Name)) { entities = entities.Where(en => en.Status.Name == request.Status.Name); } if (true == request.StatusNames?.Any()) { entities = entities.Where(en => en.Status.Name.In(request.StatusNames)); } if (!DocTools.IsNullOrEmpty(request.User) && !DocTools.IsNullOrEmpty(request.User.Id)) { entities = entities.Where(en => en.User.Id == request.User.Id); } if (true == request.UserIds?.Any()) { entities = entities.Where(en => en.User.Id.In(request.UserIds)); } if (!DocTools.IsNullOrEmpty(request.WorkType) && !DocTools.IsNullOrEmpty(request.WorkType.Id)) { entities = entities.Where(en => en.WorkType.Id == request.WorkType.Id); } if (true == request.WorkTypeIds?.Any()) { entities = entities.Where(en => en.WorkType.Id.In(request.WorkTypeIds)); } else if (!DocTools.IsNullOrEmpty(request.WorkType) && !DocTools.IsNullOrEmpty(request.WorkType.Name)) { entities = entities.Where(en => en.WorkType.Name == request.WorkType.Name); } if (true == request.WorkTypeNames?.Any()) { entities = entities.Where(en => en.WorkType.Name.In(request.WorkTypeNames)); } entities = ApplyFilters <DocEntityTimeCard, TimeCardSearch>(request, entities); if (request.Skip > 0) { entities = entities.Skip(request.Skip.Value); } if (request.Take > 0) { entities = entities.Take(request.Take.Value); } if (true == request?.OrderBy?.Any()) { entities = entities.OrderBy(request.OrderBy); } if (true == request?.OrderByDesc?.Any()) { entities = entities.OrderByDescending(request.OrderByDesc); } }); return(entities); }
public object Post(TimeCardSearch request) => Get(request);