Exemplo n.º 1
0
        public void Create(CreateCategoryApiModel entity)
        {
            if (entity == null)
            {
                throw new ArgumentException("category to be created cannot be null!");
            }
            var category = _mapper.Map <CreateCategoryApiModel, Category>(entity);

            category.Name        = category.Name.Trim().ToUpperInvariant();
            category.Description = category.Description?.Trim().ToUpperInvariant();
            _db.Categories.Add(category);
        }
        public async Task <IActionResult> Post([FromBody] CreateCategoryApiModel model)
        {
            try
            {
                var command = _mapper.Map <CreateCategoryCommand>(model);
                var result  = await _mediator.Send(command);

                return(CreatedAtRoute("GetCategory", new { id = result.CategoryId },
                                      result));
            }
            catch (Exception e)
            {
                return(BadRequest(new { e.Message, e.InnerException }));
            }
        }