示例#1
0
        public IActionResult CreateData(EditProductCategoryViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (viewModel == null)
            {
                return(BadRequest());
            }

            var dto = _mapper.Map <EditProductCategoryViewModel, ProductCategoryDTO>(viewModel);

            if (!_appService.Add(dto))
            {
                return(BadRequest());
            }

            var fullTree = _appService.GetFullTree().ToList();

            ViewProductCategoryViewModel newViewModel = new ViewProductCategoryViewModel {
                SelectedProductCategoryId = dto.Id
            };

            newViewModel.ProductCategories = _mapper.Map <IList <ProductCategoryDTO>, IList <ProductCategoryViewModel> >(fullTree);

            return(PartialView("_TreePartial", newViewModel));
        }
        public async Task <IActionResult> ExtractProductCategoryData(string categoryName)
        {
            EditProductCategoryViewModel productCategory =
                await this.shopDbUsageService.GetProductCategoryByName(categoryName);

            return(new JsonResult(productCategory));
        }
        public async Task <IActionResult> Edit(EditProductCategoryViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var lkpService = _lookupServiceFactory.Create <ProductCategory>();
                var category   = await lkpService.GetOneById(vm.Id);

                Mapper.Map(vm).Over(category);

                await lkpService.UpdateAsync(category);
            }

            return(RedirectToAction(nameof(CategoriesController.Edit), new { slug = vm.Slug }));
        }
示例#4
0
        public IActionResult Update(int id)
        {
            EditProductCategoryDTO dto = _appService.GetDataForEdit(id);

            if (dto == null)
            {
                return(BadRequest());
            }

            EditProductCategoryViewModel viewModel = _mapper.Map <EditProductCategoryDTO, EditProductCategoryViewModel>(dto);

            if (viewModel == null)
            {
                return(BadRequest());
            }

            return(PartialView("_EditingFormPartial", viewModel));
        }
示例#5
0
        public IActionResult EditProductCategory(int id)
        {
            var productCategory = productCategoryRepository.GetById(id);

            if (productCategory == null)
            {
                ViewBag.Title        = "Edytuj kategorię produktów";
                ViewBag.ErrorMessage = "Nie znaleziono kategorii o danym identyfikatorze";

                return(View("Error"));
            }

            var model = new EditProductCategoryViewModel()
            {
                Id = id,
                ProductCategoryName = productCategory.Name
            };

            return(View(model));
        }
示例#6
0
        public IActionResult EditProductCategory(EditProductCategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var productCategory = productCategoryRepository.GetById(model.Id);

                if (productCategory == null)
                {
                    ViewBag.Title        = "Edytuj kategorię produktów";
                    ViewBag.ErrorMessage = "Nie znaleziono kategorii o danym identyfikatorze";

                    return(View("Error"));
                }

                productCategory.Name = model.ProductCategoryName;
                productCategoryRepository.Update(productCategory);
                productCategoryRepository.Save();

                return(RedirectToAction("ListProductCategories"));
            }

            return(View(model));
        }
示例#7
0
        public IActionResult Create(int?parentId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            EditProductCategoryDTO dto = _appService.GetDataForCreate(parentId);

            if (dto == null)
            {
                return(BadRequest());
            }

            EditProductCategoryViewModel viewModel = _mapper.Map <EditProductCategoryDTO, EditProductCategoryViewModel>(dto);

            if (viewModel == null)
            {
                return(BadRequest());
            }

            return(PartialView("_EditingFormPartial", viewModel));
        }