Exemple #1
0
        public void Execute(CategoryInsertDto request)
        {
            var category = new Category
            {
                Name = request.Name
            };

            _context.Categories.Add(category);
            _context.SaveChanges();
        }
Exemple #2
0
 public IActionResult Post([FromBody] CategoryInsertDto dto,
                           [FromServices] ICategoryInsertCommand command)
 {
     try
     {
         executor.ExecuteCommand(command, dto);
         return(NoContent());
     }
     catch (Exception e)
     {
         return(NotFound());
     }
 }
Exemple #3
0
        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());
        }