public void Execute(CategoryInsertDto request) { var category = new Category { Name = request.Name }; _context.Categories.Add(category); _context.SaveChanges(); }
public IActionResult Post([FromBody] CategoryInsertDto dto, [FromServices] ICategoryInsertCommand command) { try { executor.ExecuteCommand(command, dto); return(NoContent()); } catch (Exception e) { return(NotFound()); } }
public async Task <ActionResult> Add(CategoryInsertDto category) { Category newCategory = new Category(); newCategory.Name = category.Name; if (category.CategoryId != Guid.Empty) { newCategory.CategoryId = category.CategoryId; } await _service.Add(newCategory); var created = _mapper.Map <CategoryDto>(newCategory); if (ValidOperation()) { return(CreatedAtAction(nameof(GetById), new { Id = newCategory.Id, Version = "1.0" }, created)); } return(CustomResponse()); }