示例#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
        public async Task <IActionResult> Add(ProductCategory category)
        {
            await categoriesRepository.AddAsync(category);

            return(RedirectToAction("Index"));
        }