public ViewResult EditCategory(int id)
        {
            ReferenceEditCategoryViewModel model = GetEditCategoryViewModel(id);

            model.PageTitle = string.Format("Page Category Edit: {0}", model.Instance.Name);
            return(View(model));
        }
        public ActionResult EditCategory(int id, FormCollection formData)
        {
            ReferenceEditCategoryViewModel model = GetEditCategoryViewModel(id);
            // Validate input
            string             categorysInput = formData["CategorysInput"].Trim();
            List <CategoryDto> categorys      = new List <CategoryDto>();

            if (!string.IsNullOrEmpty(categorysInput))
            {
                string[] items = categorysInput.Split(',');
                foreach (string item in items)
                {
                    if (!string.IsNullOrWhiteSpace(item))
                    {
                        int itemValue;
                        if (int.TryParse(item, out itemValue))
                        {
                            categorys.Add(new CategoryDto {
                                Id = itemValue
                            });
                        }
                        else
                        {
                            ModelState.AddModelError("InputError", string.Format("Categorys input error: {0}", categorysInput));
                        }
                    }
                }
            }
            if (ModelState.IsValid)
            {
                model.Instance.ReferenceCategorys = categorys;
                IFacadeUpdateResult <ReferenceData> result = Service.SaveReferenceCategorys(model.Instance);
                if (result.IsSuccessful)
                {
                    return(RedirectToAction(DetailAction, new { id = id }));
                }
                else
                {
                    ProcUpdateResult(result.ValidationResult, result.Exception);
                }
            }
            model.PageTitle = string.Format("Page Category Edit: {0}", model.Instance.Name);
            return(View(model));
        }
        private ReferenceEditCategoryViewModel GetEditCategoryViewModel(int referenceId)
        {
            ReferenceInfoDto reference = GetReference(referenceId);

            ReferenceEditCategoryViewModel model = new ReferenceEditCategoryViewModel();

            model.Instance        = reference;
            model.FolderTree      = GetCurrentFolderTree(reference.FolderId);
            model.CurrentLanguage = CurrentLanguage;

            model.AvailableCategorys = new List <CategoryViewModel>();
            foreach (CategoryDto item in reference.Template.Categorys)
            {
                CategoryViewModel presenter = new CategoryViewModel(item);
                model.AvailableCategorys.Add(presenter);
                if (reference.ReferenceCategorys.Any(o => object.Equals(o.Id, item.Id)))
                {
                    presenter.IsSelected = true;
                }
            }

            return(model);
        }