Exemple #1
0
        public ActionResult Delete(DeleteCategoryViewModel model)
        {
            var categoryService = new CategoryService();
            var postService     = new PostService();

            var post = postService.SearchPostsByCategoryId(new SearchPostsByCategoryIdRequest {
                IdCategory = model.Id
            }).Posts;
            var childCategories = categoryService.SearchCategoriesByIdUpperCategory(new SearchCategoriesByIdUpperCategoryRequest {
                IdUpperCategory = model.Id
            }).Categories;

            if ((!childCategories.Any()) && (!post.Any()))
            {
                var result = categoryService.DeleteCategory(new DeleteCategoryRequest {
                    Id = model.Id
                });
            }
            else
            {
                if (post.Any())
                {
                    ModelState.AddModelError(string.Empty, "No se puede eliminar la categoría. Posee publicaciones asignadas.");
                }
                if (childCategories.Any())
                {
                    ModelState.AddModelError(string.Empty, "No se puede eliminar la categoría. Posee categorías hijas.");
                }
                return(View(model));
            }

            return(RedirectToAction("Index", "Category"));
        }
Exemple #2
0
        private DeleteCategoryViewModel InitializeDeleteCategoryViewModel(Category category)
        {
            // create the delete category view model
            var viewModel = new DeleteCategoryViewModel
            {
                // create the category
                Category = new Category
                {
                    // assign the category values to the view model
                    Id          = category.Id,
                    Name        = category.Name,
                    Description = category.Description,
                    ImagePath   = category.ImagePath,
                    Products    = category.Products,
                    CreateDate  = category.CreateDate,
                    CreatedBy   = category.CreatedBy,
                    UpdateDate  = category.UpdateDate,
                    UpdatedBy   = category.UpdatedBy,
                    IsDeleted   = category.IsDeleted
                },
                // set some values to handle unassigned products
                UnassignedCategoryId = _db.Categories.Single(c => c.Name == Models.Constants.CATEGORY_UNASSIGNED_PRODUCTS).Id,
                UnassignedCategory   = _db.Categories.Single(c => c.Name == Models.Constants.CATEGORY_UNASSIGNED_PRODUCTS).Name
            };

            return(viewModel);
        }
Exemple #3
0
        public void Delete(DeleteCategoryViewModel vm)
        {
            var mappedCategoryInModel = _mapper.Map <Category>(vm);

            _categoryRepo.DeleteCategory(mappedCategoryInModel);
            _categoryRepo.Save();
        }
Exemple #4
0
        public IActionResult Delete(DeleteCategoryViewModel model)
        {
            var mappedCategoryFromModel = this.mapper.Map <Category>(model);

            this.categoriesService.Delete(mappedCategoryFromModel);
            this.categoriesService.Save();
            return(this.RedirectToAction("Index", "Categories"));
        }
Exemple #5
0
        public DeleteCategoryViewModel BuildViewModel(PhotoCategory repositoryModel)
        {
            DeleteCategoryViewModel viewModel = new DeleteCategoryViewModel();

            viewModel.CategoryId   = repositoryModel.CategoryId;
            viewModel.CategoryName = repositoryModel.CategoryName;
            return(viewModel);
        }
        public IActionResult Delete(DeleteCategoryViewModel vm)
        {
            var mappedCategoryInModel = _mapper.Map <Category>(vm);

            _category.DeleteCategory(mappedCategoryInModel);
            _category.Save();
            return(RedirectToAction("Index", "Categories"));
        }
Exemple #7
0
        private DeleteCategoryViewModel GetDeleteCategoryViewModel(int?id, int?subCatNumRows, int?prodNumRows, Category category)
        {
            DeleteCategoryViewModel viewModel = InitializeDeleteCategoryViewModel(category);

            viewModel = GetDeleteCategoryDataFromDB(id, category, ref viewModel);
            viewModel = GetGridRowData(subCatNumRows, prodNumRows, ref viewModel);

            return(viewModel);
        }
        public async Task <IActionResult> Delete(int id)
        {
            ProcessResult <PhotoCategory> categoryProcessResult = await GetPhotoCategory(id);

            ModelState.AddProcessResultErrors(categoryProcessResult);
            DeleteCategoryViewModelMapper mapper    = new DeleteCategoryViewModelMapper();
            DeleteCategoryViewModel       viewModel = mapper.BuildViewModel(categoryProcessResult.Result);

            return(View(viewModel));
        }
        public PartialViewResult DeleteCategoryModal(int id)
        {
            var householdId = User.Identity.GetHouseholdId();
            var category    = _categoryManager.Get(id, householdId.Value);
            var model       = new DeleteCategoryViewModel
            {
                Id   = category.Id,
                Name = category.Name
            };

            return(PartialView(model));
        }
Exemple #10
0
        public IActionResult DeleteCategory(int forumCategoryID)
        {
            forumCategory = forumCategoryCollection.GetForumCategory(forumCategoryID);

            DeleteCategoryViewModel model = new DeleteCategoryViewModel
            {
                ForumCategoryID     = forumCategory.ForumCategoryID,
                ForumCategoryString = forumCategory.ForumCategoryString
            };

            return(View(model));
        }
Exemple #11
0
        public ActionResult ErrorDeleteUnassignedCategory(int?id)
        {
            // if no id was supplied
            if (id == null)
            {
                // return http error
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // try to get the category
            Category category = _db.Categories.Find(id);

            // if the category is null
            if (category == null)
            {
                // return 404
                return(HttpNotFound());
            }

            var viewModel = new DeleteCategoryViewModel
            {
                Category = new Category
                {
                    Id          = category.Id,
                    Name        = category.Name,
                    Description = category.Description,
                    ImagePath   = category.ImagePath,
                    CreatedBy   = category.CreatedBy,
                    CreateDate  = category.CreateDate,
                    UpdatedBy   = category.UpdatedBy,
                    UpdateDate  = category.UpdateDate,
                    IsDeleted   = category.IsDeleted,
                    Products    = category.Products
                }
            };

            if (category.CreatedBy != null)
            {
                viewModel.CreatedByUsername = _applicationDb.Users.Find(category.CreatedBy).UserName;
            }

            if (category.UpdatedBy != null)
            {
                viewModel.UpdatedByUsername = _applicationDb.Users.Find(category.UpdatedBy).UserName;
            }
            else
            {
                viewModel.UpdatedByUsername = string.Empty;
            }

            return(View(viewModel));
        }
        public ActionResult DeleteCategoryConfirmation(Guid id)
        {
            var cat       = _categoryService.Get(id);
            var subCats   = _categoryService.GetAllSubCategories(id).ToList();
            var viewModel = new DeleteCategoryViewModel
            {
                Id            = cat.Id,
                Category      = cat,
                SubCategories = subCats
            };

            return(View(viewModel));
        }
Exemple #13
0
        public DeleteCategoryViewModel GetDeleteCategoryViewModel(int?id)
        {
            Category currentCategory          = this.Context.Categories.Find(id);
            DeleteCategoryViewModel viewModel =
                Mapper.Map <Category, DeleteCategoryViewModel>(currentCategory);

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

            return(viewModel);
        }
Exemple #14
0
        public IActionResult DeleteCategory(int id, DeleteCategoryViewModel deleteCategoryViewModel)
        {
            var currCategory = this.ArtisticWorkService.GetCategoryById(id);

            if (currCategory == null)
            {
                return(RedirectToAction("Categories", "ArtisticWork", new { area = "" }));
            }

            deleteCategoryViewModel.ArtWorkCategory = this.ArtisticWorkService.GetCategoryById(id);

            return(this.View(deleteCategoryViewModel));
        }
        public async Task <IActionResult> DeleteConfirmed(DeleteCategoryViewModel viewModel)
        {
            int NewCategoryId = viewModel.NewCategoryId;

            ReassignItemsToNewCategory(viewModel.OldCategoryId, NewCategoryId);
            await _context.SaveChangesAsync();

            var costCategory = await _context.CostCategory.FindAsync(viewModel.OldCategoryId);

            _context.CostCategory.Remove(costCategory);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult Delete(DeleteCategoryViewModel model)
        {
            List <Category> _categories = _logic.GetAllCategories();

            model.Categories = _categories;


            if (model.CategoryId != Guid.Empty)
            {
                _logic.DeleteCategory(model.CategoryId);
                return(RedirectToAction("SuccesfullDelete", model));
            }

            return(View(model));
        }
Exemple #17
0
        // GET: Admin/Categories/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                throw new Exception($"Invalid URL - category's id can not be null");
            }

            DeleteCategoryViewModel viewModel = this.categoryService.GetDeleteCategoryViewModel(id);

            if (viewModel == null)
            {
                throw new Exception($"Invalid URL - there is no category with id {id}");
            }

            return(View(viewModel));
        }
Exemple #18
0
        public ActionResult Delete(int id)
        {
            var categoryService = new CategoryService();

            var result = categoryService.GetCategoryById(new GetCategoryByIdRequest {
                Id = id
            }).Category;

            var model = new DeleteCategoryViewModel
            {
                Id    = result.Id,
                Title = result.Title,
            };

            return(View(model));
        }
        // GET: CostCategories/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            int catId = id.GetValueOrDefault();

            DeleteCategoryViewModel viewModel = new DeleteCategoryViewModel {
                OldCategoryId  = catId,
                CostCategories = _context.CostCategory.ToList(),
                CostCategory   = _context.CostCategory.FirstOrDefault(c => c.Id == id)
            };

            return(View(viewModel));
        }
Exemple #20
0
        public async Task <ActionResult> Delete(DeleteCategoryViewModel viewModel)
        {
            var category = await this._categoryService.GetCategoryByIdAsync(viewModel.Id);

            if (category == null)
            {
                this.SetNotificationForUnExistingCategory();
                return(RedirectToAction(nameof(Index)));
            }

            await this._categoryService.RemoveCategoryWithPicsAsync(category);

            DeleteCategoryAndPicsFromServer(category.Name);

            this.AddNotification(NotificationMessagesRecources.msgDeleteCategory, NotificationType.SUCCESS);

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Delete(DeleteCategoryViewModel viewModel)
        {
            ProcessResult <PhotoCategory> categoryProcessResult = await GetPhotoCategory(viewModel.CategoryId);

            ModelState.AddProcessResultErrors(categoryProcessResult);
            if (ModelState.IsValid)
            {
                ProcessResult <bool> saveResult = _db.SaveRemoves(categoryProcessResult.Result);
                ModelState.AddProcessResultErrors(saveResult);
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(viewModel));
            }
        }
Exemple #22
0
 public IActionResult Delete(DeleteCategoryViewModel vm)
 {
     _category.Delete(vm);
     return(RedirectToAction("Index", "Categories"));
 }
Exemple #23
0
        private DeleteCategoryViewModel GetDeleteCategoryDataFromDB(int?id, Category category, ref DeleteCategoryViewModel viewModel)
        {
            // if we are a child category (sub-category)
            if (category.ParentId != null)
            {
                viewModel.Parent = _db.Categories.Find(category.ParentId);
            }

            // get the main category we are looking at's list of products
            viewModel.Products = _db.Products.Where(p => p.CategoryId == id).ToList();

            // get any sub categories
            viewModel.Category.Children = _db.Categories.Where(c => c.ParentId == id).OrderBy(c => c.Name).ToList();
            // if we got some children
            if (viewModel.Category.Children.Count > 0)
            {
                // get any further sub categories
                viewModel.Category.Children = GetChildren(viewModel.Category.Children, id);
            }

            // set the created by username / email value
            if (category.CreatedBy != null)
            {
                viewModel.CreatedByUsername = _applicationDb.Users.Find(category.CreatedBy).UserName;
            }

            // set the updated by username / email value
            if (category.UpdatedBy != null)
            {
                viewModel.UpdatedByUsername = _applicationDb.Users.Find(category.UpdatedBy).UserName;
            }
            else
            {
                viewModel.UpdatedByUsername = string.Empty;
            }

            return(viewModel);
        }
Exemple #24
0
        private static DeleteCategoryViewModel GetGridRowData(int?subCatNumRows, int?prodNumRows, ref DeleteCategoryViewModel viewModel)
        {
            // ensure we have a value
            if (subCatNumRows == null)
            {
                // set default of X per page (we can choose something suitable 0 gets all)
                subCatNumRows = 5;
            }

            // ensure we have a value
            if (prodNumRows == null)
            {
                // set default of X per page (we can choose something suitable 0 gets all)
                prodNumRows = 5;
            }

            viewModel.SubCategoryRowsPerCategory = Convert.ToInt32(subCatNumRows);
            viewModel.ProductRowsPerCategory     = Convert.ToInt32(prodNumRows);
            viewModel.RowOptions = Models.Constants.SMALL_GRID_ROW_OPTIONS;

            return(viewModel);
        }
 public IActionResult SuccesfullDelete(DeleteCategoryViewModel model)
 {
     return(View(model));
 }
        public async Task <IActionResult> DeleteCategory([FromBody] DeleteCategoryViewModel model)
        {
            ResultMessage <bool> deleted = await _categoryService.Delete(model.CategoryId);

            return(RedirectToDetailsController(model.CourseId, deleted.Status));
        }