public async Task <IHttpActionResult> Get(int id) { try { var product = await crudOnProducts.GetProduct(id); var viewProduct = Mapper.Map <ViewProduct>(product); return(Ok(viewProduct)); } catch (Exception ex) { return(throwExceptionToUser.Throw(ex)); } }
public async Task <List <Product> > GetUsersFavoriteProducts(string username) { if (!context.Users.Any(x => x.UserName == username)) { throw new ObjectNotFoundException(); } var usfs = context.UsersFavoriteProducts.Where(x => x.Username == username).ToList(); var products = new List <Product>(); usfs.ForEach(async x => { var product = await crudOnProducts.GetProduct(x.ProductId); products.Add(product); }); return(products); }