Example #1
0
        public EditProductCategoryDTO GetDataForEdit(int productCategoryId)
        {
            // Get product category without tracking by EF
            IQueryInclude queryObj = new QueryInclude {
                IsTracking = false
            };
            var entity = _unitOfWork.ProductCategoryRepository.GetById(productCategoryId, queryObj);

            if (entity == null)
            {
                return(null);
            }

            EditProductCategoryDTO dto = _mapper.Map <ProductCategory, EditProductCategoryDTO>(entity);

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

            // Get all parent categories that does not contain the editing product catetory
            dto.ParentCategories = GetFullTree(productCategoryId);

            return(dto);
        }
Example #2
0
        public EditProductCategoryDTO GetDataForCreate(int?parentProductCategoryId)
        {
            var dto = new EditProductCategoryDTO {
                ParentId = parentProductCategoryId
            };

            dto.ParentCategories = GetFullTree(null);
            return(dto);
        }
Example #3
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));
        }
Example #4
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));
        }