public async Task <int> Count(NotificationStatusFilter filter) { IQueryable <NotificationStatusDAO> NotificationStatuses = DataContext.NotificationStatus.AsNoTracking(); NotificationStatuses = DynamicFilter(NotificationStatuses, filter); return(await NotificationStatuses.CountAsync()); }
public async Task <ActionResult <List <Notification_NotificationStatusDTO> > > SingleListNotificationStatus([FromBody] Notification_NotificationStatusFilterDTO Notification_NotificationStatusFilterDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } NotificationStatusFilter NotificationStatusFilter = new NotificationStatusFilter(); NotificationStatusFilter.Skip = 0; NotificationStatusFilter.Take = 20; NotificationStatusFilter.OrderBy = NotificationStatusOrder.Id; NotificationStatusFilter.OrderType = OrderType.ASC; NotificationStatusFilter.Selects = NotificationStatusSelect.ALL; NotificationStatusFilter.Id = Notification_NotificationStatusFilterDTO.Id; NotificationStatusFilter.Code = Notification_NotificationStatusFilterDTO.Code; NotificationStatusFilter.Name = Notification_NotificationStatusFilterDTO.Name; List <NotificationStatus> NotificationStatuses = await NotificationStatusService.List(NotificationStatusFilter); List <Notification_NotificationStatusDTO> Notification_NotificationStatusDTOs = NotificationStatuses .Select(x => new Notification_NotificationStatusDTO(x)).ToList(); return(Notification_NotificationStatusDTOs); }
public async Task <List <NotificationStatus> > List(NotificationStatusFilter filter) { if (filter == null) { return(new List <NotificationStatus>()); } IQueryable <NotificationStatusDAO> NotificationStatusDAOs = DataContext.NotificationStatus.AsNoTracking(); NotificationStatusDAOs = DynamicFilter(NotificationStatusDAOs, filter); NotificationStatusDAOs = DynamicOrder(NotificationStatusDAOs, filter); List <NotificationStatus> NotificationStatuses = await DynamicSelect(NotificationStatusDAOs, filter); return(NotificationStatuses); }
public async Task <List <NotificationStatus> > List(NotificationStatusFilter NotificationStatusFilter) { try { List <NotificationStatus> NotificationStatuss = await UOW.NotificationStatusRepository.List(NotificationStatusFilter); return(NotificationStatuss); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(NotificationStatusService)); } return(null); }
public async Task <int> Count(NotificationStatusFilter NotificationStatusFilter) { try { int result = await UOW.NotificationStatusRepository.Count(NotificationStatusFilter); return(result); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(NotificationStatusService)); } return(0); }
public async Task <bool> ValidateId(NotificationStatus NotificationStatus) { NotificationStatusFilter NotificationStatusFilter = new NotificationStatusFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = NotificationStatus.Id }, Selects = NotificationStatusSelect.Id }; int count = await UOW.NotificationStatusRepository.Count(NotificationStatusFilter); if (count == 0) { NotificationStatus.AddError(nameof(NotificationStatusValidator), nameof(NotificationStatus.Id), ErrorCode.IdNotExisted); } return(count == 1); }
private IQueryable <NotificationStatusDAO> DynamicOrder(IQueryable <NotificationStatusDAO> query, NotificationStatusFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case NotificationStatusOrder.Id: query = query.OrderBy(q => q.Id); break; case NotificationStatusOrder.Code: query = query.OrderBy(q => q.Code); break; case NotificationStatusOrder.Name: query = query.OrderBy(q => q.Name); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case NotificationStatusOrder.Id: query = query.OrderByDescending(q => q.Id); break; case NotificationStatusOrder.Code: query = query.OrderByDescending(q => q.Code); break; case NotificationStatusOrder.Name: query = query.OrderByDescending(q => q.Name); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }
private IQueryable <NotificationStatusDAO> OrFilter(IQueryable <NotificationStatusDAO> query, NotificationStatusFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <NotificationStatusDAO> initQuery = query.Where(q => false); foreach (NotificationStatusFilter NotificationStatusFilter in filter.OrFilter) { IQueryable <NotificationStatusDAO> queryable = query; if (NotificationStatusFilter.Id != null && NotificationStatusFilter.Id.HasValue) { queryable = queryable.Where(q => q.Id, NotificationStatusFilter.Id); } if (NotificationStatusFilter.Code != null && NotificationStatusFilter.Code.HasValue) { queryable = queryable.Where(q => q.Code, NotificationStatusFilter.Code); } if (NotificationStatusFilter.Name != null && NotificationStatusFilter.Name.HasValue) { queryable = queryable.Where(q => q.Name, NotificationStatusFilter.Name); } initQuery = initQuery.Union(queryable); } return(initQuery); }
private IQueryable <NotificationStatusDAO> DynamicFilter(IQueryable <NotificationStatusDAO> query, NotificationStatusFilter 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 <NotificationStatus> > DynamicSelect(IQueryable <NotificationStatusDAO> query, NotificationStatusFilter filter) { List <NotificationStatus> NotificationStatuses = await query.Select(q => new NotificationStatus() { Id = filter.Selects.Contains(NotificationStatusSelect.Id) ? q.Id : default(long), Code = filter.Selects.Contains(NotificationStatusSelect.Code) ? q.Code : default(string), Name = filter.Selects.Contains(NotificationStatusSelect.Name) ? q.Name : default(string), }).ToListAsync(); return(NotificationStatuses); }