public IActionResult AddNew(CategoryWriteDTO category)
 {
     if (category != null)
     {
         if (category.parent_id != null)
         {
             category.parent = _repo.GetOneById(category.parent_id);
         }
         Category cat = _mapper.Map <Category>(category);
         _repo.Add(cat);
         if (_repo.SaveChanges() > 0)
         {
             return(Ok("created"));
         }
     }
     return(BadRequest());
 }
Beispiel #2
0
 public IActionResult AddNew(ProductWriteDTO product)
 {
     if (product != null)
     {
         if (product.category_id != null)
         {
             product.category = _catrepo.GetOneById(product.category_id);
             Product productNew = _mapper.Map <Product>(product);
             _repo.Add(productNew);
             if (_repo.SaveChanges() > 0)
             {
                 return(Ok("created"));
             }
         }
     }
     return(BadRequest());
 }