public bool Put(CategoryToCreateDTO categoryToCreate, int id) { Category category = _mapper.Map <Category>(categoryToCreate); category.CategoryId = id; return(_unitOfWork.CategoryRepository.Update(category)); }
public async Task <IActionResult> Put(int id, CategoryToCreateDTO categoryToCreate) { if (await _categoryService.Put(categoryToCreate, id)) { return(NoContent()); } return(BadRequest("Fail to update Product")); }
public CategoryToReturnDTO Post(CategoryToCreateDTO categoryTocreate) { Category category = _mapper.Map <Category>(categoryTocreate); if (_unitOfWork.CategoryRepository.Add(category) == true) { return(_mapper.Map <CategoryToReturnDTO>(category)); } throw new ArgumentException("Fail on creation"); }
public async Task <bool> Put(CategoryToCreateDTO category, int id) { var categoryFromRepo = await _unitOfWork.Category.GetById(id); if (categoryFromRepo == null) { throw new Exception("model doesn't exsist"); } _mapper.Map(category, categoryFromRepo); return(await _unitOfWork.SaveChanges()); }
public async Task <CategoryToReturnDTO> Post(CategoryToCreateDTO category) { var categoryToCreate = _mapper.Map <Category>(category); _unitOfWork.Category.Add(categoryToCreate); if (await _unitOfWork.SaveChanges()) { return(_mapper.Map <CategoryToReturnDTO>(categoryToCreate)); } throw new Exception("Fail on creation"); }
public async Task <IActionResult> Post([FromBody] CategoryToCreateDTO categoryToCreate) { var category = await _categoryService.Post(categoryToCreate); return(CreatedAtRoute("GetCategory", new { Id = category.CategoryId }, category)); }