Example #1
0
 public Resource.Product getParent(int id)
 {
     DB.Models.Product    product    = _context.Product.Include(p => p.ParentProduct).Where(p => p.ID == id).SingleOrDefault();
     API.Resource.Product retProduct = null;
     if (product != null)
     {
         retProduct = mapper.Map <API.Resource.Product>(product);
     }
     return(retProduct);
 }
Example #2
0
 public void updateProduct(API.Resource.Product product)
 {
     DB.Models.Product upProduct = mapper.Map <API.Resource.Product, DB.Models.Product>(product);
     DB.Models.Product frProduct = _context.Product.Where(p => p.ID == upProduct.ID).SingleOrDefault();
     frProduct.SKU = upProduct.SKU;
     frProduct.ExternalProductIdentifier = upProduct.ExternalProductIdentifier;
     frProduct.ProductTypeID             = upProduct.ProductTypeID;
     frProduct.BrandID = upProduct.BrandID;
     _context.Update(frProduct, GraphBehavior.SingleObject);
     _context.SaveChanges();
 }
Example #3
0
 public void insertProduct(API.Resource.Product product, API.Resource.ProductType type, API.Resource.Brand brand)
 {
     DB.Models.Product insertProduct = mapper.Map <DB.Models.Product>(product);
     _context.Product.Add(insertProduct);
     if (type != null && type.ID == 0)
     {
         _context.ProductType.Add(mapper.Map <DB.Models.ProductType>(type));
     }
     if (brand != null && brand.brandID == 0)
     {
         _context.Brand.Add(mapper.Map <DB.Models.Brand>(brand));
     }
 }
Example #4
0
        public API.Resource.Product createProduct(API.Resource.Product newProduct)
        {
            DB.Models.Product dbProduct = mapper.Map <DB.Models.Product>(newProduct);
            dbProduct.Created      = DateTime.Now;
            dbProduct.LastModified = DateTime.Now;

            _context.Product.Add(dbProduct);
            _context.SaveChanges();

            DB.Models.Product savedProduct = _context.Product.Where(p => p.SKU == newProduct.SKU).SingleOrDefault();
            if (savedProduct == null)
            {
                return(null);
            }
            return(mapper.Map <API.Resource.Product>(savedProduct));
        }
Example #5
0
        public IEnumerable <API.Resource.Product> getProducts(ProductQuery query, out int total)
        {
            Expression <Func <DB.Models.Product, bool> > queryAsExpre = query.asExpression();
            IQueryable <DB.Models.Product> productQuery = _context.Product
                                                          .Include(p => p.Brand)
                                                          .Include(p => p.ChannelProduct)
                                                          .ThenInclude(cp => cp.Channel)
                                                          .Include(p => p.ProductType)
                                                          .Include(p => p.RelatedProduct)
                                                          .Include(p => p.RelatedProductNavigation)
                                                          .Include(p => p.VendorProduct)
                                                          .ThenInclude(vp => vp.Vendor)
                                                          .Include(p => p.ProductAttributeOption)
                                                          .ThenInclude(pao => pao.AttributeOption)
                                                          .ThenInclude(pao => pao.Attribute)
                                                          .ThenInclude(pao => pao.AttributeType)
                                                          .Include(p => p.ProductAttributeValue)
                                                          .ThenInclude(pao => pao.Attribute)
                                                          .ThenInclude(pao => pao.AttributeType)
                                                          .Include(p => p.ParentProduct)
                                                          .Where <DB.Models.Product>(queryAsExpre);
            IQueryable <DB.Models.Product> newQuery = query.getOrdering(productQuery);
            List <DB.Models.Product>       products = newQuery
                                                      .Skip(query.page * query.results)
                                                      .Take(query.results)
                                                      .ToList();

            total = productQuery.Count();

            List <API.Resource.Product> retList = new List <Resource.Product>();

            foreach (DB.Models.Product prod in products)
            {
                API.Resource.Product newprod = mapper.Map <API.Resource.Product>(prod);
                retList.Add(newprod);
            }
            return(retList);
        }
Example #6
0
 public void insertProduct(API.Resource.Product product)
 {
     insertProduct(product, null, null);
 }
Example #7
0
 public void insertProduct(API.Resource.Product product, API.Resource.Brand brand)
 {
     insertProduct(product, null, brand);
 }
Example #8
0
 public void insertProduct(API.Resource.Product Product, API.Resource.ProductType type)
 {
     insertProduct(Product, type, null);
 }