Beispiel #1
0
        public ActionResult Index(string name, int price, int brandId, string picture, string description)
        {
            var allShoesVm = new ShoeListViewModel
            {
                Shoes = _shoesService.GetAllShoes()
            };
            var allBrandsVM = _brandServices.GetAllBrands();

            dynamic myModel = new ExpandoObject();

            myModel.AllShoes = allShoesVm.Shoes;
            myModel.Brand    = allBrandsVM;

            try
            {
                if (ModelState.IsValid)
                {
                    var shoe = new ShoeViewModel()
                    {
                        Name        = name,
                        Price       = price,
                        BrandId     = brandId,
                        PictureUrl  = picture,
                        Description = description
                    };

                    if (!string.IsNullOrWhiteSpace(shoe.Description))
                    {
                        _shoesService.AddShoe(shoe);
                    }
                }
            }
            catch (Exception)
            {
                ViewBag.Error = "Some Error";
            }

            return(View("Index", myModel));
        }
Beispiel #2
0
 public IActionResult AddShoe([FromBody] ShoeViewModel shoe)
 {
     _shoesService.AddShoe(shoe);
     return(Ok());
 }