public async Task <CategoryCreateResult> CreateCategory(CategoryCreate request) { await validator.ValidateCreateModel(request); var newCategory = mapper.MapCategory(request); await context.Categories.AddAsync(newCategory); await context.SaveChangesAsync(); return(new CategoryCreateResult() { CategoryId = newCategory.Id }); }
public async Task <CategoryUpdateResult> UpdateCategory(CategoryUpdate model) { await validator.ValidateUpdateModel(model); var toUpdate = await context.Categories.SingleOrDefaultAsync(x => x.Id == model.Id); if (toUpdate == null) { throw new ArgumentException($"Can't fine category with id {model.Id}"); } toUpdate = mapper.MapCategory(toUpdate, model); await context.SaveChangesAsync(); var categoryModel = await categoryProvider.GetCategory(model.Id); return(new CategoryUpdateResult() { Category = categoryModel }); }