Beispiel #1
0
        public IActionResult AddShoes(AddShoeViewModel viewModel)
        {
            if (viewModel.ImageUrl == null || viewModel.ProductName == null)
            {
                AddShoeViewModel model = new AddShoeViewModel();
                return(RedirectToAction("AddShoes", new { viewModel = model }));
            }
            else
            {
                Shoe shoe = new Shoe {
                    ModelName   = viewModel.ProductName,
                    Price       = viewModel.Price,
                    Discription = viewModel.Discription,
                    ImageUrl    = viewModel.ImageUrl,
                    BrandId     = _context.Brands.Single(o => o.BrandName == viewModel.Brand).Id,
                    UseWayId    = _context.UseWays.Single(o => o.WayName == viewModel.UseWay).Id,
                    Amount38    = viewModel.Amount38,
                    Amount39    = viewModel.Amount39,
                    Amount40    = viewModel.Amount40,
                    Amount41    = viewModel.Amount41,
                    Amount42    = viewModel.Amount42,
                    Amount43    = viewModel.Amount43,
                    Amount44    = viewModel.Amount44,
                    Amount45    = viewModel.Amount45
                };

                _context.Shoes.Add(shoe);
                _context.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
        }
Beispiel #2
0
        public IActionResult Add()
        {
            var listOfCategories = context.Categories.ToList();
            AddShoeViewModel addShoeViewModel = new AddShoeViewModel(listOfCategories);

            return(View(addShoeViewModel));
        }
Beispiel #3
0
 public async Task <IActionResult> AddShoes()
 {
     if (await CheckRoles())
     {
         _logger.LogInformation($"Processing request {this.Request.Path} at {DateTime.Now:hh:mm:ss}");
         ViewBag.Brands  = _context.Brands.ToList();
         ViewBag.UseWays = _context.UseWays.ToList();
         AddShoeViewModel viewModel = new AddShoeViewModel();
         return(View(viewModel));
     }
     _logger.LogError($"Error in {this.Request.Path} at {DateTime.Now:hh:mm:ss}");
     return(NotFound());
 }
Beispiel #4
0
        public IActionResult Add(AddShoeViewModel addShoeViewModel)
        {
            if (ModelState.IsValid)
            {
                ShoeCategory catg = context.Categories.Single(s => s.ID == addShoeViewModel.CategoryID);
                // Add the new cheese to my existing cheeses
                Shoe Shoe = new Shoe
                {
                    Name        = addShoeViewModel.Name,
                    Description = addShoeViewModel.Description,
                    Category    = catg
                };

                context.Shoes.Add(Shoe);
                context.SaveChanges();

                return(Redirect("/Shoe"));
            }

            return(View(addShoeViewModel));
        }