示例#1
0
        //Given a UPC code, delete Product from Products table
        //Returns a boolean
        public bool Delete_Product_By_UPC(long product_UPC, ref string msg)
        {
            var ret = true;

            using (var context = new DataModel.WarehouseContext())
            {
                // Delete Product from the database using product UPC
                DataModel.Product product = new DataModel.Product {
                    Product_UPC = product_UPC
                };
                context.Products.Attach(product);
                context.Products.Remove(product);

                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result != 1)
                {
                    msg = "Product was not deleted";
                    ret = false;
                }
                else
                {
                    msg = "Product deleted";
                }
            }

            return(ret);
        }
        protected override IList <EventHandlerBase> GetHandlers(DataModel.Product entity)
        {
            var h = base.GetHandlers(entity);

            h.Add(new ProductTagRemoveChangeHandler(entity, GetOperationContext(), UnitOfWork));
            return(h);
        }
示例#3
0
        //Given a Product object, update the Products table on Product_ID
        //Returns a boolean
        public bool Update_Product_By_Product_ID(DataModel.Product product_in)
        {
            var ret = true;

            using (var context = new DataModel.WarehouseContext())
            {
                // Get and update Product
                var product = context.Products.SingleOrDefault(p => p.Product_ID == product_in.Product_ID);
                if (product != null)
                {
                    product.Product_Name  = product_in.Product_Name;
                    product.Product_Price = product_in.Product_Price;
                    product.Product_UPC   = product_in.Product_UPC;
                    product.CategoryRefID = product_in.CategoryRefID;

                    //Apply change
                    context.Products.Attach(product);
                    context.Entry(product).State = System.Data.Entity.EntityState.Modified;

                    //Check execution of transaction - we expect 1 change to have occurred
                    var execution_result = context.SaveChanges();
                    if (execution_result != 1)
                    {
                        ret = false;
                    }
                }
                else
                {
                    ret = false;
                }
            }

            return(ret);
        }
示例#4
0
        /// <summary>
        /// MSCS 701-702 Topics in Math Sts, & Comp Sci
        /// Service Oriented Architecture (SOA)
        /// Spring 2019
        /// Omar Waller, Andrew Jacobson
        ///
        /// Description: This class contains queries to the Products table in the database configured in the app.config file. .

        /// </summary>

        //Given a Product object, add to Products table
        //Returns a boolean
        public bool Create(DataModel.Product product_in, ref string msg)
        {
            var ret = true;

            using (var context = new DataModel.WarehouseContext())
            {
                // Create and save a new Product
                var newProduct = new DataModel.Product();

                newProduct.Product_Name  = product_in.Product_Name;
                newProduct.Product_Price = product_in.Product_Price;
                newProduct.Product_UPC   = product_in.Product_UPC;
                newProduct.CategoryRefID = product_in.CategoryRefID;

                //Add the Product
                context.Products.Add(newProduct);

                //Check execution of transaction - we expect 1 change to have occurred
                if (context.SaveChanges() != 1)
                {
                    msg = "Issue adding product";
                    ret = false;
                }
                else
                {
                    msg = "Product created";
                }
            }

            return(ret);
        }
示例#5
0
        //Given an ID, get Product from Products table
        //Returns Product object
        public DataModel.Product Get_Product_By_ID(int product_ID)
        {
            //Create Product object
            DataModel.Product product = new DataModel.Product();

            using (var context = new DataModel.WarehouseContext())
            {
                try
                {
                    // Get Product from database
                    var product_Qs = context.Products.SingleOrDefault(p => p.Product_ID == product_ID);
                    if (product_Qs != null)
                    {
                        product.Product_ID    = product_Qs.Product_ID;
                        product.Product_Name  = product_Qs.Product_Name;
                        product.Product_Price = product_Qs.Product_Price;
                        product.Product_UPC   = product_Qs.Product_UPC;
                        product.CategoryRefID = product_Qs.CategoryRefID;

                        return(product);
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("No item found", ex);
                }
            }

            return(product);
        }
示例#6
0
 private Product MapToDto(DataModel.Product product)
 {
     return(new Product
     {
         ProductId = product.ProductID,
         Name = product.Name,
         ProductNumber = product.ProductNumber
     });
 }
示例#7
0
 private DataModel.Product ConvertDBProductToBLProduct(Product product)
 {
     DataModel.Product Product = new DataModel.Product();
     Product.Id              = product.Id;
     Product.Name            = product.Name;
     Product.Price           = product.Price;
     Product.Description     = product.Description;
     Product.ProductCategory = (DataModel.Category)Enum.Parse(typeof(DataModel.Category), product.Category.ProductCategory);
     return(Product);
 }
示例#8
0
        public Products ConvertDBProductsToBLProducts(List <DAL.Product> dbList)
        {
            Products products = new Products();

            foreach (var item in dbList)
            {
                DataModel.Product product = this.ConvertDBProductToBLProduct(item);
                products.ProductList.Add(product);
            }
            return(products);
        }
示例#9
0
        public void AddProduct(Product product)
        {
            using var context = new StoredbContext(_contextOptions);
            var new_product = new DataModel.Product
            {
                Name  = product.Name,
                Price = (decimal)product.Price
            };

            context.Products.Add(new_product);
            context.SaveChanges();
        }
示例#10
0
        private ShoppingCartCollection ConvertDBCartsToBLCarts(List <ShoppingCart> dbList, BestPurchaseDBEntities db)
        {
            ShoppingCartCollection carts = new ShoppingCartCollection();

            foreach (var item in dbList)
            {
                DataModel.ShoppingCart cart = new DataModel.ShoppingCart();
                Product           product   = db.Products.FirstOrDefault(c => c.Id == item.ProductId);
                DataModel.Product pro       = ConvertDBProductToBLProduct(product);
                cart.Added    = pro;
                cart.Quantity = item.Quantity;
                cart.CartId   = item.Id;
                carts.ListOfCarts.Add(cart);
            }
            return(carts);
        }
示例#11
0
        public byte[] GetProductById(int productId)
        {
            BestPurchaseDBEntities db = new BestPurchaseDBEntities();
            Product product           = db.Products.FirstOrDefault(c => c.Id == productId);

            DataModel.Product blProduct = ConvertDBProductToBLProduct(product);

            // Getting image as byte array
            MemoryStream memoryStream = new MemoryStream();

            byte[] fileContents;
            var    path = Path.Combine(HttpContext.Current.Server.MapPath("~/Pictures"),
                                       product.ImageSource);

            fileContents          = File.ReadAllBytes(path);
            blProduct.ImageSource = fileContents;
            return(Formatter.Serialize(blProduct));
        }
 public ProductNameChangeHandler(DataModel.Product entity, OperationContext context) : base(entity, context)
 {
 }
 protected override EventResult SaveChanges(DataModel.Product entity)
 {
     UnitOfWork.ProductRepository.Update(entity);
     UnitOfWork.Save();
     return(new EventResult());
 }
示例#14
0
 public ProductPropertyHandler(DataModel.Product entity, OperationContext context) : base(entity, context)
 {
 }
 public ProductTagAddChangeHandler(DataModel.Product entity, OperationContext context, IUnitOfWork unitOfWork) : base(entity, context)
 {
     UnitOfWork = unitOfWork;
 }