Example #1
0
 public void Add(Product product)
 {
     if (product.ProductItems.Any())
     {
         foreach (var productItem in product.ProductItems)
         {
             AddProductItem(productItem);
         }
     }
     _repositoryProduct.Add(product);
 }
        public IActionResult Post([FromBody] ProductViewModel product)
        {
            if (product == null)
            {
                return(BadRequest("objeto nulo"));
            }

            var p = new Product(product.Name, product.Description, product.Price);

            _repository.Add(p);
            _repository.Save();

            return(Created("api/v1/product", p));
        }
Example #3
0
        public async Task <IActionResult> Post(Product model)
        {
            try
            {
                _repo.Add(model);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/product/{model.Id}", model));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco Dados Falhou"));
            }

            return(BadRequest());
        }
Example #4
0
        //[HttpPost("/api/persons")]
        public async Task <IActionResult> SaveProduct([FromBody] Product product)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (_efCoreRepositoryProduct != null)
                {
                    await _efCoreRepositoryProduct.Add(product);

                    // await _efCoreRepositoryProduct.SaveChangesAsync();
                }
                return(CreatedAtAction("getAllProduct", new { id = product.ProductCode }, product));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #5
0
        public ActionResult New(ProductAddEditVM productmodel)
        {
            Product product = productmodel.toProduct();

            if (ModelState.IsValid)
            {
                if (product.Id == 0)
                {
                    _ProductRepository.Add(product);
                }
                else
                {
                    _ProductRepository.Edit(product);
                }


                return(RedirectToAction("Index"));
            }
            var types = _ProductTypeRepository.FindAll();

            ViewBag.Types = types;
            return(View(product));
        }
Example #6
0
        public Products Add(Products product)
        {
            var result = iRepositoryProduct.Add(mapProducts.MapFrom(product));

            return(mapProducts.MapTo(result));
        }