コード例 #1
0
        public async Task <CategoryStatusResponse> SaveCategoryAsync(Category category)
        {
            try {
                Category newAddedCategory = await categoryRepository.AddAsync(category);

                return(new CategoryStatusResponse(newAddedCategory));
            } catch (Exception ex) {
                return(new CategoryStatusResponse(ex.Message));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                await _categoriesRepository.AddAsync(category);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #3
0
        public async Task <IActionResult> Index([FromBody] CreateGategoryViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.Select(v => v.Errors)));
            }

            var sectionExist = await _sectionsRepository.Contains(vm.SectionId);

            if (sectionExist)
            {
                var category = _mapper.Map <Category>(vm);

                await _categoriesRepository.AddAsync(category);

                return(Ok());
            }

            return(BadRequest());
        }
コード例 #4
0
ファイル: Categories.cs プロジェクト: esiole/MyCosts
        public async Task <IActionResult> Add(ProductCategory category)
        {
            await categoriesRepository.AddAsync(category);

            return(RedirectToAction("Index"));
        }