public async Task <EntityResponse <Product> > Handle(GetAllGroupedQuery request, CancellationToken cancellationToken) { var response = new EntityResponse <Product> () { ReponseName = nameof(GetAllGroupedQuery), Content = new List <Product> () { } }; var entities = await _productRepository.GetAllGroupedAsync(); _mapper.Map <List <Product> > (entities); if (entities == null) { response.Status = ResponseType.Warning; response.Message = $"No {nameof(Product)}s were found."; response.Content = null; } else { response.Status = ResponseType.Success; response.Message = $"{nameof(Product)}s get successfully."; response.Content.AddRange(entities); } return(response); }
public async Task <ActionResult <EntityResponse <Product> > > GetGroupedProducts() { try { var query = new GetAllGroupedQuery(); var result = await _mediator.Send(query); return(Ok(result)); } catch (Exception ex) { var err = new EntityResponse <Product> (); err.ReponseName = nameof(GetGroupedProducts); err.Status = ResponseType.Error; err.Message = ex.Message; err.Content = null; return(Ok(err)); } }