Exemplo n.º 1
0
 public static Category ToModel(this CategoryVModel c)
 {
     return(new Category {
         Id = c.Id,
         Name = c.Name
     });
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([FromBody] CategoryVModel category)
        {
            var newCategory = category.ToModel();

            _categories.Create(newCategory, UserId);
            await _categories.SaveAsync();

            _logger.LogInformation($"User: {UserId} created a new category {newCategory}");
            return(Created(Request.Path.Value, newCategory.ToVModel()));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Update([FromBody] CategoryVModel category)
        {
            var oldCategory = await _categories.GetByIdAsync(category.Id);

            oldCategory.Name = category.Name;
            _categories.Update(oldCategory, UserId);
            await _categories.SaveAsync();

            _logger.LogInformation($"User: {UserId} modified a his category {oldCategory}");
            return(Ok(oldCategory.ToVModel()));
        }