public async Task <ActionResult <IEnumerable <LatestOrderModel> > > GetLatestOrders() { var userID = User.Claims.First(c => c.Type == "UserID").Value; var query = new GetLatestOrdersQuery(userID); var response = await _mediator.Send(query); if (response == null) { return(NotFound("Cannot get any available latest orders")); } return(Ok(response)); }
public async Task <IEnumerable <LatestOrderModel> > Handle(GetLatestOrdersQuery request, CancellationToken cancellationToken) { var user = await _userManager.FindByIdAsync(request.UserID); var cardID = user.CartID; var latestOrders = _orderService.GetAllByCartID(cardID); List <LatestOrderModel> results = new List <LatestOrderModel>(); foreach (var order in latestOrders) { results.Add(_mapper.Map <LatestOrderModel>(order)); } return(results); }