Пример #1
0
        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
            });
        }
Пример #2
0
        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
            });
        }