Ejemplo n.º 1
0
        public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            var categoryToDestroy = this.Data.Categories.All().FirstOrDefault(c => c.Id == model.Id);

            var results = new List <CategoryAdminViewModel>();

            if (categoryToDestroy != null && ModelState.IsValid)
            {
                foreach (var ticket in categoryToDestroy.Tickets.ToList())
                {
                    foreach (var comment in ticket.Comments.ToList())
                    {
                        this.Data.Comments.Delete(comment);
                    }

                    this.Data.Tickets.Delete(ticket);
                }

                this.Data.Categories.Delete(categoryToDestroy);

                this.Data.SaveChanges();
            }

            return(Content(""));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Category(CategoryAdminViewModel categoryViewModel)
        {
            var category = _categoryMapper.ToCategory(categoryViewModel);
            await _categoryProvider.ChangeCategoryAsync(category);

            return(RedirectToAction("listCategories", "Home"));
        }
Ejemplo n.º 3
0
        public ActionResult Details(int id)
        {
            Category category            = _categoryRepository.GetById(id);
            CategoryAdminViewModel model = _mapper.Map <CategoryAdminViewModel>(category);

            return(View(model));
        }
Ejemplo n.º 4
0
        public JsonResult Create([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            if (this.Data.Categories.All().Any(c => c.Name.ToLower() == model.Name.ToLower()))
            {
                ModelState.AddModelError("Name", "There is a category with this name already!");
                return(Json(ModelState));
            }

            var results = new List <CategoryAdminViewModel>();

            if (ModelState.IsValid)
            {
                Category category = new Category()
                {
                    Name = model.Name
                };

                this.Data.Categories.Add(category);

                this.Data.SaveChanges();

                results.Add(new CategoryAdminViewModel
                {
                    Id   = category.Id,
                    Name = category.Name
                });
            }

            return(Json(results.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public ViewResult Edit(int id)
        {
            Category category            = _categoryRepository.GetById(id);
            CategoryAdminViewModel model = _mapper.Map <CategoryAdminViewModel>(category);

            return(View(model));
        }
        public ActionResult Delete([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            this.Data.Categories.Remove(model.Id);
            this.Data.SaveChanges();

            return this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState));
        }
        public ActionResult Delete([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            this.Data.Categories.Delete(model.Id);
            this.Data.SaveChanges();

            return(this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState)));
        }
Ejemplo n.º 8
0
 public ActionResult Create(CategoryAdminViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View("Edit", model));
     }
     _categoryRepository.Create(Mapper.Map <Category>(model));
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 9
0
        public void Edit_WhenNotValidModelPassed_ValidationFails(string name, string description)
        {
            _model = new CategoryAdminViewModel
            {
                Description = description,
                Name        = name
            };

            IsModelStateValidationWorks(_model);
        }
        public ActionResult Delete([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                Data.Categories.Delete(model.Id);
                Data.SaveChanges();
            }

            return this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState));
        }
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var category = this.Data.Categories.Find(model.Id);
                category.Name = model.Name;
                this.Data.SaveChanges();
            }

            return this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState));
        }
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var category = this.Data.Categories.Find(model.Id);
                category.Name = model.Name;
                this.Data.SaveChanges();
            }

            return(this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState)));
        }
Ejemplo n.º 13
0
        public ActionResult Update([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var category = Mapper.Map <Category>(model);
                this.Data.Categories.Update(category);
                this.Data.SaveChanges();
            }

            return(this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState)));
        }
        public ActionResult Create([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var category = Mapper.Map<Category>(model);
                Data.Categories.Add(category);
                Data.SaveChanges();
            }

            return this.Json(new[] { model }.ToDataSourceResult(request, this.ModelState));
        }
Ejemplo n.º 15
0
        public ActionResult Edit(CategoryAdminViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            _categoryRepository.Update(_mapper.Map <Category>(model));
            _unitOfWork.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult AtricleCategoriesUpdate([DataSourceRequest]DataSourceRequest request, CategoryAdminViewModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                var updatedCategory = Mapper.Map<AtricleCategory>(model);

                var result = this.categoryService.UpdateCategory(updatedCategory);

                Mapper.Map(result, model);
            }

            return Json(new[] { model }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Edit(CategoryAdminViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            var user = await this.userManager.GetUserAsync(this.User);

            await this.categoriesService.EditAsync(model.Id, model.Name, model.PictureUrl, model.IsDeleted, user.Id);

            return(this.RedirectToAction(nameof(this.All)));
        }
Ejemplo n.º 18
0
        public override void Setup()
        {
            base.Setup();
            _model = new CategoryAdminViewModel();
            _categoryRepository = new Mock <ICategoryRepository>();
            _controller         = new CategoryAdminController(
                _categoryRepository.Object,
                _userManager.Object,
                _unitOfWork.Object,
                _mapper.Object
                );

            MockHttpContext();
        }
Ejemplo n.º 19
0
        public JsonResult Update([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            var categoryToUpdate = this.Data.Categories.All().FirstOrDefault(c => c.Id == model.Id);

            var results = new List <CategoryAdminViewModel>();

            if (categoryToUpdate != null && ModelState.IsValid)
            {
                categoryToUpdate.Name = model.Name;

                this.Data.SaveChanges();

                results.Add(new CategoryAdminViewModel
                {
                    Id   = categoryToUpdate.Id,
                    Name = categoryToUpdate.Name
                });
            }

            return(Json(results.ToDataSourceResult(request), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Index(string postType = "page")
        {
            var _postType = await _postTypeService.GetBySlugAsync(postType);

            var model = new CategoryAdminViewModel {
                PostTypeId = _postType.Id
            };

            var result = await _categoryService.GetGridDataAsync(
                _postType.Id, new CategoryGridOptions {
                PageSize   = 10,
                StartIndex = 0
            });

            var langs = await _languageService.GetAllAsync();

            model.Languages = langs.Select(_ => _.Adapt <LanguageItemViewModel>());

            model.Items = result.Items
                          .Select(_ => _.Adapt <CategoryListItemViewModel>());

            return(View(model));
        }
        public JsonResult UpdateCategory([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel category)
        {
            if (category != null && ModelState.IsValid)
            {
                var existingCategory = this.Data.Categories.GetById(category.Id);
                existingCategory.Name = category.Name;
                this.Data.Categories.Update(existingCategory);
                this.Data.SaveChanges();
            }

            return(Json((new[] { category }.ToDataSourceResult(request, ModelState)), JsonRequestBehavior.AllowGet));
        }
        public JsonResult CreateCategory([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel category)
        {
            if (category != null && ModelState.IsValid)
            {
                Category categoryToBase = new Category()
                {
                    Name = category.Name,
                };

                this.Data.Categories.Add(categoryToBase);
                this.Data.SaveChanges();
                category.Id = categoryToBase.Id;
            }

            return(Json(new[] { category }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet));
        }
        public ActionResult AtricleCategoriesUpdate([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel model)
        {
            if (ModelState.IsValid && model != null)
            {
                var updatedCategory = Mapper.Map <AtricleCategory>(model);

                var result = this.categoryService.UpdateCategory(updatedCategory);

                Mapper.Map(result, model);
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
        public JsonResult DeleteCategory([DataSourceRequest] DataSourceRequest request, CategoryAdminViewModel category)
        {
            var categoryToDelete = this.Data.Categories.GetById(category.Id);

            if (categoryToDelete != null)
            {
                foreach (var ticket in categoryToDelete.Tickets.ToList())
                {
                    foreach (var comment in ticket.Comments.ToList())
                    {
                        this.Data.Comments.Delete(comment);
                    }

                    this.Data.Tickets.Delete(ticket);
                }

                this.Data.Categories.Delete(categoryToDelete);
                this.Data.SaveChanges();
            }

            return(Json(new[] { category }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 25
0
 public Category ToCategory(CategoryAdminViewModel categoryViewModel)
 {
     return(_mapper.Map <CategoryAdminViewModel, Category>(categoryViewModel));
 }