Exemplo n.º 1
0
        // GET: Product
        public ActionResult Index()
        {
            ProductBll bll = new ProductBll();

            List <ComplexEntity <Product, ProductCategory> > objs = bll.GetProductWithCategory();
            List <ProductModel> model = ProductModel.Convert(objs);

            return(View(model));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get All Products.
        /// </summary>
        public List <ProductModel> GetAllProducts()
        {
            List <ProductModel> collection = new List <ProductModel>();

            using (var context = new WOW_Assignment_ProductDBEntities1())
            {
                collection.AddRange((context.Products.ToList().Select(a => ProductModel.Convert(a))));
            }

            return(collection);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get Product.
        /// </summary>
        /// <param name="id"></param>
        public ProductModel GetProduct(int id)
        {
            ProductModel product = null;

            using (var context = new WOW_Assignment_ProductDBEntities1())
            {
                var entity = context.Products.Where(a => a.ProductID == id).ToList().FirstOrDefault();
                product = ProductModel.Convert(entity);
            }

            return(product);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add Product.
        /// </summary>
        /// <param name="model"></param>
        public bool AddProduct(ProductModel model)
        {
            outcome = false;
            using (var context = new WOW_Assignment_ProductDBEntities1())
            {
                var entity = ProductModel.Convert(model);
                context.Products.Add(entity);
                outcome = context.SaveChanges() == 1;
            }

            return(outcome);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Remove Product.
        /// </summary>
        /// <param name="model"></param>
        public bool RemoveProduct(ProductModel model)
        {
            outcome = false;
            using (var context = new WOW_Assignment_ProductDBEntities1())
            {
                if (model != null)
                {
                    var entity = ProductModel.Convert(model);
                    context.Products.Attach(entity);
                    context.Products.Remove(entity);
                    outcome = context.SaveChanges() == 1;
                }
            }

            return(outcome);
        }
Exemplo n.º 6
0
        public async Task <ProductModel> AddAsync(ProductModel productModel)
        {
            var entity = await _context.Products.Where(p => p.Id == productModel.Id).FirstOrDefaultAsync();

            Product product = productModel.Convert(entity);

            if (entity == null)
            {
                await _context.Products.AddAsync(product);
            }
            else
            {
                _context.Products.Update(product);
            }

            await _context.SaveChangesAsync();

            return(await GetByIdAsync(product.Id));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Update Product.
        /// </summary>
        /// <param name="model"></param>
        public bool UpdateProduct(ProductModel model)
        {
            outcome = false;
            using (var context = new WOW_Assignment_ProductDBEntities1())
            {
                if (model != null)
                {
                    var entity = ProductModel.Convert(model);
                    context.Products.Attach(entity);
                    var entry = context.Entry(entity);

                    entry.Property(p => p.Title).IsModified       = true;
                    entry.Property(p => p.Description).IsModified = true;
                    entry.Property(p => p.ImageURL).IsModified    = true;

                    outcome = context.SaveChanges() == 1;
                }
            }

            return(outcome);
        }