public async Task <int> Count(CustomerFeedbackFilter filter) { IQueryable <CustomerFeedbackDAO> CustomerFeedbacks = DataContext.CustomerFeedback.AsNoTracking(); CustomerFeedbacks = DynamicFilter(CustomerFeedbacks, filter); return(await CustomerFeedbacks.CountAsync()); }
public async Task <ActionResult <bool> > BulkDelete([FromBody] List <long> Ids) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } CustomerFeedbackFilter CustomerFeedbackFilter = new CustomerFeedbackFilter(); CustomerFeedbackFilter = await CustomerFeedbackService.ToFilter(CustomerFeedbackFilter); CustomerFeedbackFilter.Id = new IdFilter { In = Ids }; CustomerFeedbackFilter.Selects = CustomerFeedbackSelect.Id; CustomerFeedbackFilter.Skip = 0; CustomerFeedbackFilter.Take = int.MaxValue; List <CustomerFeedback> CustomerFeedbacks = await CustomerFeedbackService.List(CustomerFeedbackFilter); CustomerFeedbacks = await CustomerFeedbackService.BulkDelete(CustomerFeedbacks); if (CustomerFeedbacks.Any(x => !x.IsValidated)) { return(BadRequest(CustomerFeedbacks.Where(x => !x.IsValidated))); } return(true); }
public async Task <List <CustomerFeedback> > List(CustomerFeedbackFilter CustomerFeedbackFilter) { try { List <CustomerFeedback> CustomerFeedbacks = await UOW.CustomerFeedbackRepository.List(CustomerFeedbackFilter); return(CustomerFeedbacks); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CustomerFeedbackService)); } return(null); }
public async Task <int> Count(CustomerFeedbackFilter CustomerFeedbackFilter) { try { int result = await UOW.CustomerFeedbackRepository.Count(CustomerFeedbackFilter); return(result); } catch (Exception ex) { await Logging.CreateSystemLog(ex, nameof(CustomerFeedbackService)); } return(0); }
public async Task <List <CustomerFeedback> > List(CustomerFeedbackFilter filter) { if (filter == null) { return(new List <CustomerFeedback>()); } IQueryable <CustomerFeedbackDAO> CustomerFeedbackDAOs = DataContext.CustomerFeedback.AsNoTracking(); CustomerFeedbackDAOs = DynamicFilter(CustomerFeedbackDAOs, filter); CustomerFeedbackDAOs = DynamicOrder(CustomerFeedbackDAOs, filter); List <CustomerFeedback> CustomerFeedbacks = await DynamicSelect(CustomerFeedbackDAOs, filter); return(CustomerFeedbacks); }
public async Task <ActionResult <int> > Count([FromBody] CustomerFeedback_CustomerFeedbackFilterDTO CustomerFeedback_CustomerFeedbackFilterDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } CustomerFeedbackFilter CustomerFeedbackFilter = ConvertFilterDTOToFilterEntity(CustomerFeedback_CustomerFeedbackFilterDTO); CustomerFeedbackFilter = await CustomerFeedbackService.ToFilter(CustomerFeedbackFilter); int count = await CustomerFeedbackService.Count(CustomerFeedbackFilter); return(count); }
public async Task <bool> ValidateId(CustomerFeedback CustomerFeedback) { CustomerFeedbackFilter CustomerFeedbackFilter = new CustomerFeedbackFilter { Skip = 0, Take = 10, Id = new IdFilter { Equal = CustomerFeedback.Id }, Selects = CustomerFeedbackSelect.Id }; int count = await UOW.CustomerFeedbackRepository.Count(CustomerFeedbackFilter); if (count == 0) { CustomerFeedback.AddError(nameof(CustomerFeedbackValidator), nameof(CustomerFeedback.Id), ErrorCode.IdNotExisted); } return(count == 1); }
public async Task <ActionResult <List <CustomerFeedback_CustomerFeedbackDTO> > > List([FromBody] CustomerFeedback_CustomerFeedbackFilterDTO CustomerFeedback_CustomerFeedbackFilterDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } CustomerFeedbackFilter CustomerFeedbackFilter = ConvertFilterDTOToFilterEntity(CustomerFeedback_CustomerFeedbackFilterDTO); CustomerFeedbackFilter = await CustomerFeedbackService.ToFilter(CustomerFeedbackFilter); List <CustomerFeedback> CustomerFeedbacks = await CustomerFeedbackService.List(CustomerFeedbackFilter); List <CustomerFeedback_CustomerFeedbackDTO> CustomerFeedback_CustomerFeedbackDTOs = CustomerFeedbacks .Select(c => new CustomerFeedback_CustomerFeedbackDTO(c)).ToList(); return(CustomerFeedback_CustomerFeedbackDTOs); }
private async Task <bool> HasPermission(long Id) { CustomerFeedbackFilter CustomerFeedbackFilter = new CustomerFeedbackFilter(); CustomerFeedbackFilter = await CustomerFeedbackService.ToFilter(CustomerFeedbackFilter); if (Id == 0) { } else { CustomerFeedbackFilter.Id = new IdFilter { Equal = Id }; int count = await CustomerFeedbackService.Count(CustomerFeedbackFilter); if (count == 0) { return(false); } } return(true); }
private CustomerFeedbackFilter ConvertFilterDTOToFilterEntity(CustomerFeedback_CustomerFeedbackFilterDTO CustomerFeedback_CustomerFeedbackFilterDTO) { CustomerFeedbackFilter CustomerFeedbackFilter = new CustomerFeedbackFilter(); CustomerFeedbackFilter.Selects = CustomerFeedbackSelect.ALL; CustomerFeedbackFilter.Skip = CustomerFeedback_CustomerFeedbackFilterDTO.Skip; CustomerFeedbackFilter.Take = CustomerFeedback_CustomerFeedbackFilterDTO.Take; CustomerFeedbackFilter.OrderBy = CustomerFeedback_CustomerFeedbackFilterDTO.OrderBy; CustomerFeedbackFilter.OrderType = CustomerFeedback_CustomerFeedbackFilterDTO.OrderType; CustomerFeedbackFilter.Id = CustomerFeedback_CustomerFeedbackFilterDTO.Id; CustomerFeedbackFilter.CustomerId = CustomerFeedback_CustomerFeedbackFilterDTO.CustomerId; CustomerFeedbackFilter.FullName = CustomerFeedback_CustomerFeedbackFilterDTO.FullName; CustomerFeedbackFilter.Email = CustomerFeedback_CustomerFeedbackFilterDTO.Email; CustomerFeedbackFilter.PhoneNumber = CustomerFeedback_CustomerFeedbackFilterDTO.PhoneNumber; CustomerFeedbackFilter.CustomerFeedbackTypeId = CustomerFeedback_CustomerFeedbackFilterDTO.CustomerFeedbackTypeId; CustomerFeedbackFilter.Title = CustomerFeedback_CustomerFeedbackFilterDTO.Title; CustomerFeedbackFilter.SendDate = CustomerFeedback_CustomerFeedbackFilterDTO.SendDate; CustomerFeedbackFilter.Content = CustomerFeedback_CustomerFeedbackFilterDTO.Content; CustomerFeedbackFilter.StatusId = CustomerFeedback_CustomerFeedbackFilterDTO.StatusId; CustomerFeedbackFilter.CreatedAt = CustomerFeedback_CustomerFeedbackFilterDTO.CreatedAt; CustomerFeedbackFilter.UpdatedAt = CustomerFeedback_CustomerFeedbackFilterDTO.UpdatedAt; return(CustomerFeedbackFilter); }
public async Task <CustomerFeedbackFilter> ToFilter(CustomerFeedbackFilter filter) { if (filter.OrFilter == null) { filter.OrFilter = new List <CustomerFeedbackFilter>(); } if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0) { return(filter); } foreach (var currentFilter in CurrentContext.Filters) { CustomerFeedbackFilter subFilter = new CustomerFeedbackFilter(); filter.OrFilter.Add(subFilter); List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value; foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions) { if (FilterPermissionDefinition.Name == nameof(subFilter.Id)) { subFilter.Id = FilterBuilder.Merge(subFilter.Id, FilterPermissionDefinition.IdFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.CustomerId)) { subFilter.CustomerId = FilterBuilder.Merge(subFilter.CustomerId, FilterPermissionDefinition.IdFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.FullName)) { subFilter.FullName = FilterBuilder.Merge(subFilter.FullName, FilterPermissionDefinition.StringFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.Email)) { subFilter.Email = FilterBuilder.Merge(subFilter.Email, FilterPermissionDefinition.StringFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.PhoneNumber)) { subFilter.PhoneNumber = FilterBuilder.Merge(subFilter.PhoneNumber, FilterPermissionDefinition.StringFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.CustomerFeedbackTypeId)) { subFilter.CustomerFeedbackTypeId = FilterBuilder.Merge(subFilter.CustomerFeedbackTypeId, FilterPermissionDefinition.IdFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.Title)) { subFilter.Title = FilterBuilder.Merge(subFilter.Title, FilterPermissionDefinition.StringFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.SendDate)) { subFilter.SendDate = FilterBuilder.Merge(subFilter.SendDate, FilterPermissionDefinition.DateFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.Content)) { subFilter.Content = FilterBuilder.Merge(subFilter.Content, FilterPermissionDefinition.StringFilter); } if (FilterPermissionDefinition.Name == nameof(subFilter.StatusId)) { subFilter.StatusId = FilterBuilder.Merge(subFilter.StatusId, FilterPermissionDefinition.IdFilter); } if (FilterPermissionDefinition.Name == nameof(CurrentContext.UserId) && FilterPermissionDefinition.IdFilter != null) { if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.IS.Id) { } if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.ISNT.Id) { } } } } return(filter); }
private IQueryable <CustomerFeedbackDAO> OrFilter(IQueryable <CustomerFeedbackDAO> query, CustomerFeedbackFilter filter) { if (filter.OrFilter == null || filter.OrFilter.Count == 0) { return(query); } IQueryable <CustomerFeedbackDAO> initQuery = query.Where(q => false); foreach (CustomerFeedbackFilter CustomerFeedbackFilter in filter.OrFilter) { IQueryable <CustomerFeedbackDAO> queryable = query; if (CustomerFeedbackFilter.Id != null && CustomerFeedbackFilter.Id.HasValue) { queryable = queryable.Where(q => q.Id, CustomerFeedbackFilter.Id); } if (CustomerFeedbackFilter.CustomerId != null && CustomerFeedbackFilter.CustomerId.HasValue) { queryable = queryable.Where(q => q.CustomerId.HasValue).Where(q => q.CustomerId, CustomerFeedbackFilter.CustomerId); } if (CustomerFeedbackFilter.FullName != null && CustomerFeedbackFilter.FullName.HasValue) { queryable = queryable.Where(q => q.FullName, CustomerFeedbackFilter.FullName); } if (CustomerFeedbackFilter.Email != null && CustomerFeedbackFilter.Email.HasValue) { queryable = queryable.Where(q => q.Email, CustomerFeedbackFilter.Email); } if (CustomerFeedbackFilter.PhoneNumber != null && CustomerFeedbackFilter.PhoneNumber.HasValue) { queryable = queryable.Where(q => q.PhoneNumber, CustomerFeedbackFilter.PhoneNumber); } if (CustomerFeedbackFilter.CustomerFeedbackTypeId != null && CustomerFeedbackFilter.CustomerFeedbackTypeId.HasValue) { queryable = queryable.Where(q => q.CustomerFeedbackTypeId.HasValue).Where(q => q.CustomerFeedbackTypeId, CustomerFeedbackFilter.CustomerFeedbackTypeId); } if (CustomerFeedbackFilter.Title != null && CustomerFeedbackFilter.Title.HasValue) { queryable = queryable.Where(q => q.Title, CustomerFeedbackFilter.Title); } if (CustomerFeedbackFilter.SendDate != null && CustomerFeedbackFilter.SendDate.HasValue) { queryable = queryable.Where(q => q.SendDate.HasValue).Where(q => q.SendDate, CustomerFeedbackFilter.SendDate); } if (CustomerFeedbackFilter.Content != null && CustomerFeedbackFilter.Content.HasValue) { queryable = queryable.Where(q => q.Content, CustomerFeedbackFilter.Content); } if (CustomerFeedbackFilter.StatusId != null && CustomerFeedbackFilter.StatusId.HasValue) { queryable = queryable.Where(q => q.StatusId.HasValue).Where(q => q.StatusId, CustomerFeedbackFilter.StatusId); } initQuery = initQuery.Union(queryable); } return(initQuery); }
private IQueryable <CustomerFeedbackDAO> DynamicFilter(IQueryable <CustomerFeedbackDAO> query, CustomerFeedbackFilter filter) { if (filter == null) { return(query.Where(q => false)); } query = query.Where(q => !q.DeletedAt.HasValue); if (filter.CreatedAt != null && filter.CreatedAt.HasValue) { query = query.Where(q => q.CreatedAt, filter.CreatedAt); } if (filter.UpdatedAt != null && filter.UpdatedAt.HasValue) { query = query.Where(q => q.UpdatedAt, filter.UpdatedAt); } if (filter.Id != null && filter.Id.HasValue) { query = query.Where(q => q.Id, filter.Id); } if (filter.CustomerId != null && filter.CustomerId.HasValue) { query = query.Where(q => q.CustomerId.HasValue).Where(q => q.CustomerId, filter.CustomerId); } if (filter.FullName != null && filter.FullName.HasValue) { query = query.Where(q => q.FullName, filter.FullName); } if (filter.Email != null && filter.Email.HasValue) { query = query.Where(q => q.Email, filter.Email); } if (filter.PhoneNumber != null && filter.PhoneNumber.HasValue) { query = query.Where(q => q.PhoneNumber, filter.PhoneNumber); } if (filter.CustomerFeedbackTypeId != null && filter.CustomerFeedbackTypeId.HasValue) { query = query.Where(q => q.CustomerFeedbackTypeId.HasValue).Where(q => q.CustomerFeedbackTypeId, filter.CustomerFeedbackTypeId); } if (filter.Title != null && filter.Title.HasValue) { query = query.Where(q => q.Title, filter.Title); } if (filter.SendDate != null && filter.SendDate.HasValue) { query = query.Where(q => q.SendDate == null).Union(query.Where(q => q.SendDate.HasValue).Where(q => q.SendDate, filter.SendDate)); } if (filter.Content != null && filter.Content.HasValue) { query = query.Where(q => q.Content, filter.Content); } if (filter.StatusId != null && filter.StatusId.HasValue) { query = query.Where(q => q.StatusId.HasValue).Where(q => q.StatusId, filter.StatusId); } query = OrFilter(query, filter); return(query); }
private async Task <List <CustomerFeedback> > DynamicSelect(IQueryable <CustomerFeedbackDAO> query, CustomerFeedbackFilter filter) { List <CustomerFeedback> CustomerFeedbacks = await query.Select(q => new CustomerFeedback() { Id = filter.Selects.Contains(CustomerFeedbackSelect.Id) ? q.Id : default(long), IsSystemCustomer = filter.Selects.Contains(CustomerFeedbackSelect.IsSystemCustomer) ? q.IsSystemCustomer : default(bool), CustomerId = filter.Selects.Contains(CustomerFeedbackSelect.Customer) ? q.CustomerId : default(long?), FullName = filter.Selects.Contains(CustomerFeedbackSelect.FullName) ? q.FullName : default(string), Email = filter.Selects.Contains(CustomerFeedbackSelect.Email) ? q.Email : default(string), PhoneNumber = filter.Selects.Contains(CustomerFeedbackSelect.PhoneNumber) ? q.PhoneNumber : default(string), CustomerFeedbackTypeId = filter.Selects.Contains(CustomerFeedbackSelect.CustomerFeedbackType) ? q.CustomerFeedbackTypeId : default(long?), Title = filter.Selects.Contains(CustomerFeedbackSelect.Title) ? q.Title : default(string), SendDate = filter.Selects.Contains(CustomerFeedbackSelect.SendDate) ? q.SendDate : default(DateTime?), Content = filter.Selects.Contains(CustomerFeedbackSelect.Content) ? q.Content : default(string), StatusId = filter.Selects.Contains(CustomerFeedbackSelect.Status) ? q.StatusId : default(long?), Customer = filter.Selects.Contains(CustomerFeedbackSelect.Customer) && q.Customer != null ? new Customer { Id = q.Customer.Id, Code = q.Customer.Code, Name = q.Customer.Name, Phone = q.Customer.Phone, Address = q.Customer.Address, NationId = q.Customer.NationId, ProvinceId = q.Customer.ProvinceId, DistrictId = q.Customer.DistrictId, WardId = q.Customer.WardId, CustomerTypeId = q.Customer.CustomerTypeId, Birthday = q.Customer.Birthday, Email = q.Customer.Email, ProfessionId = q.Customer.ProfessionId, CustomerResourceId = q.Customer.CustomerResourceId, SexId = q.Customer.SexId, StatusId = q.Customer.StatusId, CompanyId = q.Customer.CompanyId, ParentCompanyId = q.Customer.ParentCompanyId, TaxCode = q.Customer.TaxCode, Fax = q.Customer.Fax, Website = q.Customer.Website, NumberOfEmployee = q.Customer.NumberOfEmployee, BusinessTypeId = q.Customer.BusinessTypeId, Investment = q.Customer.Investment, RevenueAnnual = q.Customer.RevenueAnnual, IsSupplier = q.Customer.IsSupplier, Descreption = q.Customer.Descreption, Used = q.Customer.Used, RowId = q.Customer.RowId, } : null, CustomerFeedbackType = filter.Selects.Contains(CustomerFeedbackSelect.CustomerFeedbackType) && q.CustomerFeedbackType != null ? new CustomerFeedbackType { Id = q.CustomerFeedbackType.Id, Code = q.CustomerFeedbackType.Code, Name = q.CustomerFeedbackType.Name, } : null, Status = filter.Selects.Contains(CustomerFeedbackSelect.Status) && q.Status != null ? new Status { Id = q.Status.Id, Code = q.Status.Code, Name = q.Status.Name, } : null, }).ToListAsync(); return(CustomerFeedbacks); }
private IQueryable <CustomerFeedbackDAO> DynamicOrder(IQueryable <CustomerFeedbackDAO> query, CustomerFeedbackFilter filter) { switch (filter.OrderType) { case OrderType.ASC: switch (filter.OrderBy) { case CustomerFeedbackOrder.Id: query = query.OrderBy(q => q.Id); break; case CustomerFeedbackOrder.IsSystemCustomer: query = query.OrderBy(q => q.IsSystemCustomer); break; case CustomerFeedbackOrder.Customer: query = query.OrderBy(q => q.CustomerId); break; case CustomerFeedbackOrder.FullName: query = query.OrderBy(q => q.FullName); break; case CustomerFeedbackOrder.Email: query = query.OrderBy(q => q.Email); break; case CustomerFeedbackOrder.PhoneNumber: query = query.OrderBy(q => q.PhoneNumber); break; case CustomerFeedbackOrder.CustomerFeedbackType: query = query.OrderBy(q => q.CustomerFeedbackTypeId); break; case CustomerFeedbackOrder.Title: query = query.OrderBy(q => q.Title); break; case CustomerFeedbackOrder.SendDate: query = query.OrderBy(q => q.SendDate); break; case CustomerFeedbackOrder.Content: query = query.OrderBy(q => q.Content); break; case CustomerFeedbackOrder.Status: query = query.OrderBy(q => q.StatusId); break; } break; case OrderType.DESC: switch (filter.OrderBy) { case CustomerFeedbackOrder.Id: query = query.OrderByDescending(q => q.Id); break; case CustomerFeedbackOrder.IsSystemCustomer: query = query.OrderByDescending(q => q.IsSystemCustomer); break; case CustomerFeedbackOrder.Customer: query = query.OrderByDescending(q => q.CustomerId); break; case CustomerFeedbackOrder.FullName: query = query.OrderByDescending(q => q.FullName); break; case CustomerFeedbackOrder.Email: query = query.OrderByDescending(q => q.Email); break; case CustomerFeedbackOrder.PhoneNumber: query = query.OrderByDescending(q => q.PhoneNumber); break; case CustomerFeedbackOrder.CustomerFeedbackType: query = query.OrderByDescending(q => q.CustomerFeedbackTypeId); break; case CustomerFeedbackOrder.Title: query = query.OrderByDescending(q => q.Title); break; case CustomerFeedbackOrder.SendDate: query = query.OrderByDescending(q => q.SendDate); break; case CustomerFeedbackOrder.Content: query = query.OrderByDescending(q => q.Content); break; case CustomerFeedbackOrder.Status: query = query.OrderByDescending(q => q.StatusId); break; } break; } query = query.Skip(filter.Skip).Take(filter.Take); return(query); }