public async Task <ResultDataList <CategoryDetailViewModel> > SearchAsync(string filterExpression, int?pageIndex, int pageSize = 20, string culture = "fr") { if (string.IsNullOrEmpty(filterExpression)) { return(new ResultDataList <CategoryDetailViewModel>(false)); } var lambda = System.Linq.Dynamic.DynamicExpression.ParseLambda <Category, bool>(filterExpression); var func = lambda.Compile(); var data = await _repository.SearchAsync(func, pageIndex, pageSize); var translations = await _repositoryTranslation.AllAsync(); if (data.Any()) { var result = data.Select((c) => { var detail = new CategoryDetailViewModel(c); detail.SetTranslation(translations.FirstOrDefault(x => x.Name == c.Name && x.Language == culture)); return(detail); }).ToList(); return(PagineData(result, pageIndex, pageSize)); } return(new ResultDataList <CategoryDetailViewModel>(false)); }
public async Task<ResultDataList<CategoryDetailViewModel>> ListAsync(int? pageIndex, int pageSize = 20, string culture = "fr") { var categories = await _repository.ListAsync(pageIndex, pageSize); var translations = await _repositoryTranslation.AllAsync(); if (categories.Any()) { var result = categories.Select((c) => { var detail = new CategoryDetailViewModel(c); detail.SetTranslation(translations.FirstOrDefault(x => x.Name == c.Name && x.Language == culture)); return detail; }).ToList(); return PagineData(result, pageIndex, pageSize); } return new ResultDataList<CategoryDetailViewModel>(false, "NO CATEGORY FOUND"); }
public async Task<RequestResultWithData<CategoryDetailViewModel>> GetByIdAsync([FromRoute]Guid id, string culture = "fr") { if (id == Guid.Empty) return new RequestResultWithData<CategoryDetailViewModel>(false, "ID EMPTY"); var category = await _repository.GetByIdAsync(id); var translations = await _repositoryTranslation.SearchAsync(x => x.Name == category.Name && x.Language == culture, 0, 20); var categoryDetail = new CategoryDetailViewModel(category); if (!translations.Any()) { return new RequestResultWithData<CategoryDetailViewModel>(false, "NO TRANSLATION"); } categoryDetail.SetTranslation(translations.FirstOrDefault()); return new RequestResultWithData<CategoryDetailViewModel>(true, categoryDetail); }
public async Task <IActionResult> ListAsync(int?pageIndex, int pageSize = 20, string culture = "fr") { var categories = await _repository.ListAsync(pageIndex, pageSize); var translations = await _repositoryTranslation.AllAsync(); if (categories.Any()) { var result = categories.Select((c) => { var detail = new CategoryDetailViewModel(c); detail.SetTranslation(translations.FirstOrDefault(x => x.Name == c.Name && x.Language == culture)); return(detail); }).ToList(); return(new OkObjectResult(PagineData(result, pageIndex, pageSize))); } return(new BadRequestResult()); }
public async Task <IActionResult> GetByIdAsync([FromRoute] Guid id, string culture = "fr") { if (id == Guid.Empty) { return(new BadRequestResult()); } var category = await _repository.GetByIdAsync(id); var translations = await _repositoryTranslation.SearchAsync(x => x.Name == category.Name && x.Language == culture, 0, 20); var categoryDetail = new CategoryDetailViewModel(category); if (!translations.Any()) { return(new NotFoundResult()); } categoryDetail.SetTranslation(translations.FirstOrDefault()); return(new OkObjectResult(new RequestResultWithData <CategoryDetailViewModel>(true, categoryDetail))); }