public async Task <IActionResult> Add(AddChildCategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.ParentCategories = this.parentCategoryService.GetParentCategories().ToList();

                return(this.View(model));
            }

            var childCategory = this.childCategoryService
                                .CreateChildCategory(model.Name, model.Description, (int)model.ParentId);

            if (model.FormImage != null)
            {
                var imagePath = string.Format(GlobalConstants.CHILD_CATEGORY_PATH_TEMPLATE, childCategory.Id);
                using (var stream = new FileStream(imagePath, FileMode.Create))
                {
                    await model.FormImage.CopyToAsync(stream);
                }

                this.childCategoryService.AddImageUrl(childCategory.Id);
            }

            return(this.RedirectToAction(nameof(All)));
        }
Exemple #2
0
        public IActionResult Add()
        {
            var parentCategories = this.parentCategoryService.GetCategories().ToList();

            var addViewModel = new AddChildCategoryViewModel
            {
                ParentCategories = parentCategories
            };

            return(View(addViewModel));
        }
Exemple #3
0
        public IActionResult Add(AddChildCategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.ParentCategories = this.parentCategoryService.GetCategories().ToList();

                return(this.View(model));
            }

            var childCategory = this.childCategoryService
                                .CreateChildCategory(model.Name, (int)model.ParentId, model.ImageUrl);



            return(this.RedirectToAction(nameof(All)));
        }