コード例 #1
0
        public bool AddShoes(ShoesAddViewModel shoesVM)
        {
            //Shoes shoes = _mapper.Map<Shoes>(shoesVM);
            Brand brand = _brandRepository.GetById(shoesVM.BrandId);

            if (brand != null)
            {
                Shoes shoes = new Shoes()
                {
                    Name        = shoesVM.Name,
                    Brand       = brand,
                    Color       = shoesVM.Color,
                    IsAvaiable  = true,
                    Description = shoesVM.Description,
                    Price       = shoesVM.Price,
                    Sex         = shoesVM.Sex
                };

                _shoesRepository.Add(shoes);

                foreach (var img in shoesVM.Images)
                {
                    _imageRepository.Add(new Image()
                    {
                        IsShoes     = true,
                        Url         = img,
                        Description = shoes.Name + "'s image",
                        OwnId       = shoes.Id
                    });
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
        public async Task <IActionResult> PostShoe([FromBody] Customer newShoe)
        {
            _repo.Add(newShoe);

            var response = await _repo.SaveAll();

            if (response)
            {
                return(Created("/shoe", newShoe));
            }

            return(NotFound());
        }