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

                return(this.View(model));
            }

            this.childCategoryService.EditChildCategory(model.Id, model.Name,
                                                        model.Description, (int)model.ParentCategoryId);

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

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

            return(RedirectToAction(nameof(All)));
        }
Exemplo n.º 2
0
        public IActionResult Edit(EditChildCategoryViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.ParentCategories = this.parentCategoryService.GetCategories().ToList();

                return(this.View(model));
            }

            this.childCategoryService.EditChildCategory(model.Id, model.Name, (int)model.ParentCategoryId, model.ImageUrl);

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