Ejemplo n.º 1
0
        private void Init()
        {
            var p = new Product();
            p.Id = 1;
            p.Name="Samsung Galaxy S6 edge";
            p.Category = "T-Mobile";
            p.Color = "black";
            p.Details ="Reimagined Design Inside and Out";
            p.Price = 600;
            p.Stock = 5;
            productsList.Add(p);

            p = new Product();
            p.Id = 2;
            p.Name = "Samsung Galaxy Note Edge";
            p.Category = "T-Mobile";
            p.Color = "black";
            p.Details = "Reimagined Design Inside and Out";
            p.Price = 550;
            p.Stock = 10;
            productsList.Add(p);

            p = new Product();
            p.Id = 3;
            p.Name = "Samsung Galaxy Note II ";
            p.Category = "Sprint";
            p.Color = "gray";
            p.Details = "Reimagined Design Inside and Out";
            p.Price = 850;
            p.Stock = 7;
            productsList.Add(p);
        }
Ejemplo n.º 2
0
 public void EditProduct(Product p)
 {
     var prod = productsList.Find(i => i.Id == p.Id);
     prod.Name = p.Name;
     prod.Category = p.Category;
     prod.Color = p.Color;
     prod.Details = p.Details;
     prod.Price = p.Price;
     prod.Stock = p.Stock;
 }
Ejemplo n.º 3
0
        public void AddProduct(Product p)
        {
            string categoryName = p.Category;
            int categoryId = getCategoryId(categoryName);
            if (categoryId != CATEGORYNOTFOUND)
            {
                using (var db = new EntitySamsung())
                {
                    Samsung_Product product = new Samsung_Product(p.Name, categoryId, p.Color, (int)p.Price, p.Stock, p.Details);
                    db.Samsung_Product.Add(product);
                    db.SaveChanges();

                }
            }
        }
Ejemplo n.º 4
0
 public void EditProduct(Product p)
 {
     using (var db = new EntitySamsung())
     {
         var item = db.Samsung_Product.Find(p.Id);
         if (item != null)
         {
             item.name = p.Name;
             item.price = p.Price;
             item.stock = p.Stock;
             item.color = p.Color;
             item.details = p.Details;
             item.categoryId = getCategoryId(p.Category);
             db.SaveChanges();
         }
     }
 }
Ejemplo n.º 5
0
        public List<Product> GetAllProducts()
        {
            //return productsList;

            List<Product> productList = new List<Product>();
            List<Samsung_Product> sProductList = new List<Samsung_Product>();
            using (var db = new EntitySamsung())
            {
                sProductList = db.Samsung_Product.ToList();

            }

            foreach(Samsung_Product sProduct in sProductList)
            {
                Product product = new Product(sProduct.id, sProduct.name, getCategoryName((int)sProduct.categoryId), sProduct.color, sProduct.details, (int)sProduct.price, (int)sProduct.stock);
                productList.Add(product);
            }
            return productList;
        }
Ejemplo n.º 6
0
 public void EditProduct(Product p)
 {
     /*var prod = productsList.Find(i => i.Id == p.Id);
     prod.Name = p.Name;
     prod.Category = p.Category;
     prod.Color = p.Color;
     prod.Details = p.Details;
     prod.Price = p.Price;
     prod.Stock = p.Stock;*/
     using (var db = new EntitySamsung())
     {
         var products = db.Samsung_Product.Where(i => i.id == p.Id).ToList();
         var item = products[0];
         item.name = p.Name;
         item.categoryId = getCategoryId(p.Category);
         item.color = p.Color;
         item.details = p.Details;
         item.price = p.Price;
         item.stock = p.Stock;
         db.SaveChanges();
     }
 }
Ejemplo n.º 7
0
 public Product GetProduct(int id)
 {
     //return productsList.Find(p => p.Id == id);
     using (var db = new EntitySamsung())
     {
         var item = db.Samsung_Product.Where(p => p.id == id);
         if (item.Count() == 0)
         {
             return null;
         }
         else
         {
             var product = item.First();
             Product p = new Product(product.id, product.name, getCategoryName((int)product.categoryId), product.color, product.details, (int)product.price, (int)product.stock);
             return p;
         }
     }
 }
Ejemplo n.º 8
0
 public void RemoveProduct(Product p)
 {
     //productsList.Remove(p);
     int categoryId = getCategoryId(p.Category);
     Samsung_Product product = new Samsung_Product(p.Id,p.Name, categoryId, p.Color, (int)p.Price, p.Stock, p.Details);
     using (var db = new EntitySamsung())
     {
         db.Samsung_Product.Remove(product);
         db.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 public void RemoveProduct(Product p)
 {
     productsList.Remove(p);
 }
Ejemplo n.º 10
0
 public void AddProduct(Product p)
 {
     productsList.Add(p);
 }
Ejemplo n.º 11
0
 public static void EditProduct(ProductVM productVM)
 {
     ProductMapper productMapper = new ProductMapper();
     Product inputProduct = new Product(productVM.Id, productVM.Name, productVM.Category, productVM.Color, productVM.Details, productVM.Price, productVM.Stock);
     productMapper.EditProduct(inputProduct);
 }