示例#1
0
        public IActionResult AddWear(AddWearViewModel viewModel)
        {
            if (viewModel.ImageUrl == null || viewModel.ProductName == null)
            {
                AddWearViewModel model = new AddWearViewModel();
                return(RedirectToAction("AddWear", new { viewModel = model }));
            }
            else
            {
                WearProduct wear = new WearProduct
                {
                    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,
                    AmountS     = viewModel.AmountS,
                    AmountM     = viewModel.AmountM,
                    AmountL     = viewModel.AmountL,
                    AmountXL    = viewModel.AmountXL,
                    AmountXXL   = viewModel.AmountXXL
                };

                _context.WearProducts.Add(wear);
                _context.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
        }
示例#2
0
 public async Task <IActionResult> AddWear()
 {
     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();
         AddWearViewModel viewModel = new AddWearViewModel();
         return(View(viewModel));
     }
     _logger.LogError($"Error in {this.Request.Path} at {DateTime.Now:hh:mm:ss}");
     return(NotFound());
 }