public async Task <int> Count(EmailStatusFilter filter) { IQueryable <EmailStatusDAO> EmailStatuses = DataContext.EmailStatus.AsNoTracking(); EmailStatuses = DynamicFilter(EmailStatuses, filter); return(await EmailStatuses.CountAsync()); }
public async Task <List <EmailStatus> > List(EmailStatusFilter EmailStatusFilter) { try { List <EmailStatus> EmailStatuss = await UOW.EmailStatusRepository.List(EmailStatusFilter); return(EmailStatuss); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(EmailStatusService)); } return(null); }
public async Task <int> Count(EmailStatusFilter EmailStatusFilter) { try { int result = await UOW.EmailStatusRepository.Count(EmailStatusFilter); return(result); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(EmailStatusService)); } return(0); }
public async Task <List <EmailStatus> > List(EmailStatusFilter filter) { if (filter == null) { return(new List <EmailStatus>()); } IQueryable <EmailStatusDAO> EmailStatusDAOs = DataContext.EmailStatus.AsNoTracking(); EmailStatusDAOs = DynamicFilter(EmailStatusDAOs, filter); EmailStatusDAOs = DynamicOrder(EmailStatusDAOs, filter); List <EmailStatus> EmailStatuses = await DynamicSelect(EmailStatusDAOs, filter); return(EmailStatuses); }
public async Task <bool> ValidateId(EmailStatus EmailStatus) { EmailStatusFilter EmailStatusFilter = new EmailStatusFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = EmailStatus.Id }, Selects = EmailStatusSelect.Id }; int count = await UOW.EmailStatusRepository.Count(EmailStatusFilter); if (count == 0) { EmailStatus.AddError(nameof(EmailStatusValidator), nameof(EmailStatus.Id), ErrorCode.IdNotExisted); } return(count == 1); }
private IQueryable <EmailStatusDAO> DynamicOrder(IQueryable <EmailStatusDAO> query, EmailStatusFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case EmailStatusOrder.Id: query = query.OrderBy(q => q.Id); break; case EmailStatusOrder.Code: query = query.OrderBy(q => q.Code); break; case EmailStatusOrder.Name: query = query.OrderBy(q => q.Name); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case EmailStatusOrder.Id: query = query.OrderByDescending(q => q.Id); break; case EmailStatusOrder.Code: query = query.OrderByDescending(q => q.Code); break; case EmailStatusOrder.Name: query = query.OrderByDescending(q => q.Name); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }
private IQueryable <EmailStatusDAO> OrFilter(IQueryable <EmailStatusDAO> query, EmailStatusFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <EmailStatusDAO> initQuery = query.Where(q => false); foreach (EmailStatusFilter EmailStatusFilter in filter.OrFilter) { IQueryable <EmailStatusDAO> queryable = query; if (EmailStatusFilter.Id != null && EmailStatusFilter.Id.HasValue) { queryable = queryable.Where(q => q.Id, EmailStatusFilter.Id); } if (EmailStatusFilter.Code != null && EmailStatusFilter.Code.HasValue) { queryable = queryable.Where(q => q.Code, EmailStatusFilter.Code); } if (EmailStatusFilter.Name != null && EmailStatusFilter.Name.HasValue) { queryable = queryable.Where(q => q.Name, EmailStatusFilter.Name); } initQuery = initQuery.Union(queryable); } return(initQuery); }
private IQueryable <EmailStatusDAO> DynamicFilter(IQueryable <EmailStatusDAO> query, EmailStatusFilter filter) { if (filter == null) { return(query.Where(q => false)); } if (filter.Id != null && filter.Id.HasValue) { query = query.Where(q => q.Id, filter.Id); } if (filter.Code != null && filter.Code.HasValue) { query = query.Where(q => q.Code, filter.Code); } if (filter.Name != null && filter.Name.HasValue) { query = query.Where(q => q.Name, filter.Name); } query = OrFilter(query, filter); return(query); }
private async Task <List <EmailStatus> > DynamicSelect(IQueryable <EmailStatusDAO> query, EmailStatusFilter filter) { List <EmailStatus> EmailStatuses = await query.Select(q => new EmailStatus() { Id = filter.Selects.Contains(EmailStatusSelect.Id) ? q.Id : default(long), Code = filter.Selects.Contains(EmailStatusSelect.Code) ? q.Code : default(string), Name = filter.Selects.Contains(EmailStatusSelect.Name) ? q.Name : default(string), }).ToListAsync(); return(EmailStatuses); }