internal void AddItemToDB(ProductsCreateVM product)
        {
            Products x = new Products();

            x.Brand       = product.Brand;
            x.Description = product.Description;
            x.ImgUrl      = product.ImgUrl;
            x.Price       = product.Price;
            x.Name        = product.Name;
            context.Products.Add(x);
            context.SaveChanges();

            var productId = GetProductID(x);

            foreach (var item in product.SelectedTemperValues)
            {
                Products2Stores p2s = new Products2Stores()
                {
                    ProductId = productId,
                    StoreId   = item
                };
                context.Products2Stores.Add(p2s);
            }
            context.SaveChanges();
        }
        public IActionResult Create(ProductsCreateVM product)
        {
            if (!ModelState.IsValid)
            {
                return(View(product));
            }

            service.AddItemToDB(product);
            return(RedirectToAction(nameof(Create)));
        }
Exemplo n.º 3
0
        internal void Create(ProductsCreateVM viewmodel)
        {
            // Convert viewmodel to db model
            context.Contents.Add(new Contents
            {
                ProductName          = viewmodel.ProductName,
                OptionalQuantityInfo = viewmodel.OptionalQuantityInfo,
                StoreSection         = viewmodel.SelectedStoreSection,
            });

            context.SaveChanges();
        }
        internal ProductsCreateVM GetAllStoresFromDBForPCreateVM()
        {
            Stores[] x         = GetAllStoresFromDB();
            var      viewModel = new ProductsCreateVM();

            viewModel.TemperItems = new SelectListItem[x.Length];

            for (int i = 0; i < x.Length; i++)
            {
                viewModel.TemperItems[i] = new SelectListItem
                {
                    Value = $"{x[i].Id.ToString()}",
                    Text  = $"{x[i].StoreName}"
                };
            }

            return(viewModel);
        }
Exemplo n.º 5
0
        public IActionResult Create(ProductsCreateVM viewmodel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewmodel));
            }

            service.Create(viewmodel);

            if (viewmodel.SubmitInfo == "Done")
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(RedirectToAction(nameof(Create)));
            }
        }
Exemplo n.º 6
0
        //static List<Product> shoppingList = new List<Product>
        //{
        //    new Product {Id = id++, ProductName = "Banan", OptionalQuantityInfo = "1 klase", StoreSection = 1},
        //    new Product {Id = id++, ProductName = "Äpplen", OptionalQuantityInfo = "ca 1 kg", StoreSection = 1},
        //    new Product {Id = id++, ProductName = "Havregryn", OptionalQuantityInfo = "", StoreSection = 6},
        //    new Product {Id = id++, ProductName = "Ägg", OptionalQuantityInfo = "6 ägg", StoreSection = 2},
        //    new Product {Id = id++, ProductName = "Mjölk", OptionalQuantityInfo = "", StoreSection = 3},
        //    new Product {Id = id++, ProductName = "Apelsinjuice", OptionalQuantityInfo = "", StoreSection = 3},
        //    new Product {Id = id++, ProductName = "Choklad", OptionalQuantityInfo = "Lindt 55%", StoreSection = 9},
        //    new Product {Id = id++, ProductName = "Blåbär", OptionalQuantityInfo = "Frysta", StoreSection = 8},
        //    new Product {Id = id++, ProductName = "Ost", OptionalQuantityInfo = "Grana Padano", StoreSection = 5},
        //    new Product {Id = id++, ProductName = "Kyckling", OptionalQuantityInfo = "Hel kyckling", StoreSection = 5},
        //};

        internal ProductsCreateVM GetProductsForCreate()
        {
            var viewModel = new ProductsCreateVM
            {
                StoreSection = new SelectListItem[]
                {
                    new SelectListItem {
                        Value = "1", Text = "1. Fruits & Veggies", Selected = true
                    },
                    new SelectListItem {
                        Value = "2", Text = "2. Bread, Cookies, Coffee, Tee"
                    },
                    new SelectListItem {
                        Value = "3", Text = "3. Dairy & Juice"
                    },
                    new SelectListItem {
                        Value = "4", Text = "4. Frozen foods"
                    },
                    new SelectListItem {
                        Value = "5", Text = "5. Meat & Cheese"
                    },
                    new SelectListItem {
                        Value = "6", Text = "6. Dry goods & Canned food"
                    },
                    new SelectListItem {
                        Value = "7", Text = "7. Toiletries"
                    },
                    new SelectListItem {
                        Value = "8", Text = "8. Nuts, Berries, Ice Cream"
                    },
                    new SelectListItem {
                        Value = "9", Text = "9. Candy & Magazines"
                    },
                }
            };

            return(viewModel);
        }