Ejemplo n.º 1
0
        public ProductFull GetFullProduct(int productId)
        {
            using (EF.APShopContext context = new EF.APShopContext())
            {
                UnitOfWork uow = new UnitOfWork(context);

                EF.Product  EfProduct   = uow.Products.GetFullProduct(productId);
                ProductFull productFull = new ProductFull();

                var productDetailEntity = EfProduct.ProductDetails.SingleOrDefault();
                productFull.Details = _mapper.Map <ProductDetails>(productDetailEntity);
                productFull.Product = _mapper.Map <Product>(EfProduct);

                return(productFull);
            }
        }
Ejemplo n.º 2
0
        public int AddProduct(ProductFull fullProduct)
        {
            using (EF.APShopContext context = new EF.APShopContext())
            {
                UnitOfWork        uow              = new UnitOfWork(context);
                EF.Product        dbProduct        = _mapper.Map <EF.Product>(fullProduct.Product);
                EF.ProductDetails dbProductDetails = _mapper.Map <EF.ProductDetails>(fullProduct.Details);
                dbProduct.IsActive = true;

                dbProduct.ProductDetails.Add(dbProductDetails);
                uow.Products.AddProduct(dbProduct);

                uow.Commit();

                return(dbProduct.Id);
            }
        }