public static Category ToModel(this CategoryVModel c) { return(new Category { Id = c.Id, Name = c.Name }); }
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())); }
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())); }