Ejemplo n.º 1
0
        public void SaveMeal(AllMeals allMeals)
        {
            var first  = dBContext.FirstDishes.FirstOrDefault(x => x.Id == allMeals.Id && x.Name == allMeals.Name);
            var second = dBContext.SecondDishes.FirstOrDefault(x => x.Id == allMeals.Id && x.Name == allMeals.Name);
            var salad  = dBContext.Salads.FirstOrDefault(x => x.Id == allMeals.Id && x.Name == allMeals.Name);

            if (first != null)
            {
                first.Name        = allMeals.Name;
                first.Price       = allMeals.Price;
                first.Description = allMeals.Description;
                dBContext.SaveChanges();
            }
            if (second != null)
            {
                second.Description = allMeals.Description;
                second.Name        = allMeals.Name;
                second.Price       = allMeals.Price;
                dBContext.SaveChanges();
            }
            if (salad != null)
            {
                salad.Description = allMeals.Description;
                salad.Name        = allMeals.Name;
                salad.Price       = allMeals.Price;
                dBContext.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public ActionResult Create(Product entity)
        {
            if (!ModelState.IsValid)
            {
            }

            if (db.Products.Any(x => x.Id == entity.Id))
            {
                ViewBag.Message = "This Product Already Exists.";
                return(View(entity));
            }

            if (entity.BrandName == null)
            {
                ViewBag.Message = "Please Enter Brand Name";
                return(View(entity));
            }

            if (entity.ModelNo == null)
            {
                ViewBag.Message = "Please Enter Model Number.";
                return(View(entity));
            }

            db.Products.Add(entity);

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 public ActionResult Edit(Products products)
 {
     if (ModelState.IsValid)
     {
         db.Entry(products).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(products));
 }
 public IActionResult Post([FromBody] Products products)
 {
     if (ModelState.IsValid)
     {
         productsDBContext.Products.Add(products);
         productsDBContext.SaveChanges(true);
         return(Ok("Records added"));
     }
     return(BadRequest(ModelState));
 }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "ProductId,Name,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.ProductsDB.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Ejemplo n.º 6
0
 public int Add(Entity.Product Product)
 {
     try
     {
         _context.Products.Add(Product);
         _context.SaveChanges();
         return(Product.Id);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 7
0
        public int Add(ProductOption ProductOption)
        {
            try
            {
                _context.ProductOptions.Add(ProductOption);
                _context.SaveChanges();

                return(ProductOption.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public bool DeleteProduct(int productID)
 {
     try
     {
         var product = (from result in productsDBContext.Products
                        where result.ProductID == productID
                        select result).FirstOrDefault();
         if (product != null)
         {
             productsDBContext.Products.Remove(product);
             productsDBContext.SaveChanges();
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 9
0
 private void CreateProducts(ProductsDBContext dbContext)
 {
     for (int i = 1; i <= 10; i++)
     {
         dbContext.Products.Add(new Product()
         {
             Id        = i,
             Name      = Guid.NewGuid().ToString(),
             Inventory = i + 10,
             Price     = (decimal)(i * 3.14)
         });
     }
     dbContext.SaveChanges();
 }
Ejemplo n.º 10
0
        public IActionResult Delete(int id)
        {
            var product = _productsDbContext.Products.SingleOrDefault(m => m.ProductId == id);

            if (product is null)
            {
                return(NotFound("No record found"));
            }
            try
            {
                _productsDbContext.Products.Remove(product);
                _productsDbContext.SaveChanges(true);

                return(Ok("Product deleted...."));
            }
            catch (Exception ex)
            {
                return(NotFound("no record found"));
            }
        }
        /// <summary>
        /// Seed data In Memory database.
        /// </summary>
        /// <param name="productRepository">The product repository.</param>
        private void SeedDatabase(ProductsDBContext context)
        {
            // Add products
            context.Products.Add(new Products.Entity.Product {
                Id = 1, Name = "Samsung Galaxy S20", Description = "Latest smartphone from Samsung", Price = 1599.99M, DeliveryPrice = 9.99M
            });
            context.Products.Add(new Products.Entity.Product {
                Id = 2, Name = "Apple iPhone X", Description = "Latest smartphone from Apple", Price = 1999.99M, DeliveryPrice = 19.99M
            });
            context.Products.Add(new Products.Entity.Product {
                Id = 3, Name = "Samsung Galaxy S Fold", Description = "foldable smartphone from Samsung", Price = 1599.99M, DeliveryPrice = 9.99M
            });

            // Add Product Options
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 1, ProductId = 1, Name = "128 GB Cosmic Gray", Description = "128 GB"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 2, ProductId = 1, Name = "256 GB Blood Red", Description = "256 GB"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 3, ProductId = 1, Name = "512 GB Cherry Pink", Description = "512 GB"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 4, ProductId = 2, Name = "64 GB Black", Description = "64 GB"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 5, ProductId = 2, Name = "512 GB Gray", Description = "512 GB Gray"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 6, ProductId = 3, Name = "128 GB Gray", Description = "128 GB"
            });
            context.ProductOptions.Add(new Products.Entity.ProductOption {
                Id = 7, ProductId = 3, Name = "256 GB Red", Description = "256 GB"
            });

            context.SaveChanges();
        }
Ejemplo n.º 12
0
 private void SeedData()
 {
     if (!dbContext.Products.Any())
     {
         dbContext.Products.Add(new DB.Product()
         {
             Id = 1, Name = "Keyboard", Price = 20, Inventory = 100
         });
         dbContext.Products.Add(new DB.Product()
         {
             Id = 2, Name = "Mouse", Price = 5, Inventory = 200
         });
         dbContext.Products.Add(new DB.Product()
         {
             Id = 3, Name = "Monitor", Price = 150, Inventory = 1000
         });
         dbContext.Products.Add(new DB.Product()
         {
             Id = 4, Name = "CPU", Price = 200, Inventory = 2000
         });
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 13
0
        public void SaveOrder(Order order, Cart cart)
        {
            string clientOrder = "";

            if (cart.FirstDishes.Count() > 0)
            {
                foreach (var t in cart.FirstDishes)
                {
                    clientOrder += t.Meal.Name + ",";
                }
            }
            if (cart.SecondDishes.Count() > 0)
            {
                foreach (var t in cart.SecondDishes)
                {
                    clientOrder += t.Meal.Name + ",";
                }
            }
            if (cart.Salads.Count() > 0)
            {
                foreach (var t in cart.Salads)
                {
                    clientOrder += t.Meal.Name + ",";
                }
            }

            context.Order.Add(new Order()
            {
                Name             = order.Name,
                Address          = order.Address,
                OrderDate        = DateTime.Now,
                OrderDescription = clientOrder,
                Snipped          = order.Snipped == true ? order.Snipped : false
            });
            context.SaveChanges();
            Orders.Append(order);
        }
Ejemplo n.º 14
0
 public void AddProduct(Product product)
 {
     productsDbContext.Products.Add(product);
     productsDbContext.SaveChanges(true);
 }
Ejemplo n.º 15
0
 public void AddProduct(Products products)
 {
     _productsDBContext.Products.Add(products);
     _productsDBContext.SaveChanges(true);
 }
Ejemplo n.º 16
0
 public void AddProduct(Product product)
 {
     _context.Products.Add(product);
     _context.SaveChanges();
 }