Ejemplo n.º 1
0
        public ActionResult Create(DiyProjectModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                var diyProject = model.ToEntity();
                diyProject.CreatedOnUtc = DateTime.UtcNow;
                _diyService.InsertDiyProject(diyProject);

                //search engine name
                model.SeName = diyProject.ValidateSeName(model.SeName, diyProject.Title, true);
                _urlRecordService.SaveSlug(diyProject, model.SeName, 0);

                //locales
                UpdateLocales(diyProject, model);
                _diyService.UpdateDiyProject(diyProject);

                SuccessNotification(_localizationService.GetResource("Toi.Plugin.Misc.DoItYourself.DiyProject.Added"));
                return continueEditing ? RedirectToAction("Edit", new { id = diyProject.Id }) : RedirectToAction("List");
            }
            //parent diyProjectGroups
            model.DiyGroups = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } };
            if (model.DiyGroupId > 0)
            {
                var parentBranchGroup = _diyService.GetDiyGroupById(model.DiyGroupId);
                if (parentBranchGroup != null && !parentBranchGroup.Deleted)
                    model.DiyGroups.Add(new DropDownItem { Text = parentBranchGroup.GetFormattedBreadCrumb(_diyService), Value = parentBranchGroup.Id.ToString() });
                else
                    model.DiyGroupId = 0;
            }
            return View(model);
        }
Ejemplo n.º 2
0
        public ActionResult Edit(DiyProjectModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews))
                return AccessDeniedView();

            var diyProject = _diyService.GetDiyProjectById(model.Id);
            if (diyProject == null)
                //No news item found with the specified id
                return RedirectToAction("List");

            if (ModelState.IsValid)
            {
                diyProject = model.ToEntity(diyProject);
                _diyService.UpdateDiyProject(diyProject);

                //search engine name
                model.SeName = diyProject.ValidateSeName(model.SeName, diyProject.Title, true);
                _urlRecordService.SaveSlug(diyProject, model.SeName, 0);

                //locales
                UpdateLocales(diyProject, model);
                _diyService.UpdateDiyProject(diyProject);

                SuccessNotification(_localizationService.GetResource("Toi.Plugin.Misc.DoItYourself.DiyProject.Updated"));
                return continueEditing ? RedirectToAction("Edit", new { id = diyProject.Id }) : RedirectToAction("List");
            }
            PrepareDiyProjectModel(model);
            //parent diyProjectGroups
            model.DiyGroups = new List<DropDownItem> { new DropDownItem { Text = "[None]", Value = "0" } };
            if (model.DiyGroupId > 0)
            {
                var parentBranchGroup = _diyService.GetDiyGroupById(model.DiyGroupId);
                if (parentBranchGroup != null && !parentBranchGroup.Deleted)
                    model.DiyGroups.Add(new DropDownItem { Text = parentBranchGroup.GetFormattedBreadCrumb(_diyService), Value = parentBranchGroup.Id.ToString() });
                else
                    model.DiyGroupId = 0;
            }
            return View(model);
        }