Пример #1
0
        public ActionResult <CollectionResponse <Product> > Get(string id)
        {
            var response = new CollectionResponse <Product>();

            try
            {
                var products = (string.IsNullOrEmpty(id)
                        ? _dacProduct.All()
                        : new[] { _dacProduct.Single(id) })
                               .ToList();

                response.Collections = products
                                       .Select(p => new Product
                {
                    Id     = p.Id,
                    Name   = p.Name,
                    Price  = p.Price,
                    Images = _dacProductImage
                             .Where(pi => pi.ProductId.Equals(p.Id))
                             .Select(pi => pi.Url)
                             .ToList(),
                    CategoryName = _dacProductCategory.Single(p.CategoryId)?
                                   .Name ?? string.Empty
                })
                                       .ToList();

                response.Status.SetSuccess();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                response.Status.SetError(e);
            }

            return(response);
        }
Пример #2
0
 public ActionResult <IEnumerable <Data.Entity.Product> > Get()
 {
     return(_dacProduct.All().ToList());
 }