public ActionResult Create(FormCollection formData) { SubsiteCreateDto instance = new SubsiteCreateDto(); SubsiteCreateViewModel model = new SubsiteCreateViewModel(instance); UpdateModel(instance, formData); if (ModelState.IsValid) { int sort = 201; if (!instance.DefaultLanguageId.HasValue) { instance.DefaultLanguageId = CmsRegister.MIN_LANGUAGE_ID; } int locationId = CmsRegister.MIN_LOCATION_ID; if (instance.DefaultLocationId != null) { locationId = instance.DefaultLocationId.Value; } int categoryId = CmsRegister.MAX_CATEGORY_ID; FolderTreeData tree = CreateFolderTreeOfSupplier(instance.Name, instance.ServiceLandingName, instance.ServiceLandingSlug, instance.EventLandingName, instance.EventLandingSlug, CmsRegister.CONTENT_FOLDER_ID, sort, categoryId, locationId, false); IFacadeUpdateResult <FolderData> result = Service.SaveSubsiteWhole(tree, Convert(instance)); if (result.IsSuccessful) { return(RedirectToAction(IndexAction)); } else { ProcUpdateResult(result.ValidationResult, result.Exception); } } return(View(model)); }
public IFacadeUpdateResult <FolderData> SaveSubsiteBatch(FolderTreeData folderTree, SubsiteData subSite) { UnitOfWork.BeginTransaction(); // 1. Save parent folder folderTree.Folder.IsSubsiteRoot = true; FacadeUpdateResult <FolderData> result = SaveFolderTree(folderTree); if (result.IsSuccessful) { // 2. Save SubsiteData subSite.SubsiteFolderId = result.Result.Id; IFacadeUpdateResult <SubsiteData> subSiteResult = SubsiteSystem.SaveSubsite(subSite); result.ValidationResult.Merge(subSiteResult.ValidationResult); if (subSiteResult.IsSuccessful) { UnitOfWork.CommitTransaction(); } else { UnitOfWork.RollbackTransaction(); } } else { UnitOfWork.RollbackTransaction(); } return(result); }
public IFacadeUpdateResult <FolderData> SaveSubsiteWhole(FolderTreeData folderTree, SubsiteDto subsite) { using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CMSDataStoreKey)) { SubsiteBatchFacade facade = new SubsiteBatchFacade(uow); return(facade.SaveSubsiteBatch(folderTree, SubsiteConverter.ConvertToData(subsite))); } }
private FolderTreeData CreateFolderTreeOfSupplier(string supplierName, string serviceLandingName, string serviceLandingSlug, string eventLandingName, string eventLandingSlug, int parentId, int sort, int categoryId, int locationId, bool allowLevel2References) { FolderTreeData tree = new FolderTreeData(); // level 1 folder node string slug = supplierName.ToSlug(); tree.Folder = CreateFolder(supplierName, slug, sort, parentId); // level 1 references // Home page ReferenceData supplier = CreateReferenceOfSupplier(supplierName, categoryId, locationId, allowLevel2References); tree.References.Add(supplier); // Service landing page ReferenceData serviceLanding = CreateReferenceOfServiceLanding(serviceLandingName, serviceLandingSlug); tree.References.Add(serviceLanding); // Event landing page ReferenceData eventLanding = CreateReferenceOfEventLanding(eventLandingName, eventLandingSlug); tree.References.Add(eventLanding); // Start to add level 2 folder nodes // Home folder FolderTreeData sub1Tree = new FolderTreeData(); tree.SubFolders.Add(sub1Tree); sub1Tree.Folder = CreateFolder("Home", "", 1); // Service folder FolderTreeData sub2Tree = new FolderTreeData(); tree.SubFolders.Add(sub2Tree); sub2Tree.Folder = CreateFolder("Service", serviceLandingSlug, 3); // Event folder FolderTreeData sub3Tree = new FolderTreeData(); tree.SubFolders.Add(sub3Tree); sub3Tree.Folder = CreateFolder("Event", eventLandingSlug, 5); if (allowLevel2References) { // level 2 references // Service1 reference ReferenceData service1 = CreateReferenceOfService("Service 1", categoryId + CmsRegister.SERVICE_CATEGORY_OFFSET, locationId); sub2Tree.References.Add(service1); // Service2 reference ReferenceData service2 = CreateReferenceOfService("Service 2", categoryId + CmsRegister.SERVICE_CATEGORY_OFFSET, locationId); sub2Tree.References.Add(service2); // Service3 reference ReferenceData service3 = CreateReferenceOfService("Service 3", categoryId + CmsRegister.SERVICE_CATEGORY_OFFSET, locationId); sub2Tree.References.Add(service3); // event1 reference ReferenceData event1 = CreateReferenceOfEvent("Event 1", locationId); sub3Tree.References.Add(event1); } return(tree); }
public ActionResult CreateBatch(FormCollection formData) { SubsiteBatchDto instance = new SubsiteBatchDto(); SubsiteBatchCreateViewModel model = new SubsiteBatchCreateViewModel(instance); UpdateModel(instance, formData); if (ModelState.IsValid) { Random randomValue = new Random(); for (int index = 1; index <= instance.Total; index++) { string instanceName = string.Format("{0}{1}", instance.NameStem, index); int sort = 201 + index; int languageId = randomValue.Next(CmsRegister.MIN_LANGUAGE_ID, CmsRegister.MAX_LANGUAGE_ID + 1); int locationId = randomValue.Next(CmsRegister.MIN_LOCATION_ID, CmsRegister.MAX_LOCATION_ID + 1); int categoryId = randomValue.Next(CmsRegister.MIN_CATEGORY_ID, CmsRegister.MAX_CATEGORY_ID + 1); if (instance.DefaultLanguageId != null) { languageId = instance.DefaultLanguageId.Value; } if (instance.DefaultLocationId != null) { locationId = instance.DefaultLocationId.Value; } string serviceLandingName = "Service"; string serviceLandingSlug = "service"; string eventLandingName = "Event"; string eventLandingSlug = "event"; FolderTreeData tree = CreateFolderTreeOfSupplier(instanceName, serviceLandingName, serviceLandingSlug, eventLandingName, eventLandingSlug, CmsRegister.CONTENT_FOLDER_ID, sort, categoryId, locationId, true); SubsiteDto subsite = CreateSubsite(instanceName, languageId, locationId); IFacadeUpdateResult <FolderData> result = Service.SaveSubsiteWhole(tree, subsite); if (!result.IsSuccessful) { ProcUpdateResult(result.ValidationResult, result.Exception); break; } } } return(View(model)); }
public FacadeUpdateResult <FolderData> SaveFolderTree(FolderTreeData folderTree) { // 1. Save parent folder FacadeUpdateResult <FolderData> parentFolderResult = FolderSystem.SaveFolder(folderTree.Folder); if (parentFolderResult.IsSuccessful) { // 2. Save References foreach (ReferenceData reference in folderTree.References) { // Assign reference's FolderId reference.FolderId = parentFolderResult.Result.Id; FacadeUpdateResult <ReferenceData> referenceResult = ReferenceSystem.SaveReference(reference); parentFolderResult.ValidationResult.Merge(referenceResult.ValidationResult); if (referenceResult.IsSuccessful) { // Save ReferenceCategory if (reference.ReferenceCategorys.Count > 0) { ReferenceSystem.SaveReferenceCategorys(referenceResult.Result.Id, reference.ReferenceCategorys); } // Save SubitemValues IFacadeUpdateResult <ReferenceData> valueResult = SubitemValueSystem.SaveSubitemValues(referenceResult.Result.Id, reference.Values); } } // 3. Save SubFolders foreach (FolderTreeData subFolder in folderTree.SubFolders) { // Assign sub folder's ParentId subFolder.Folder.ParentId = parentFolderResult.Result.Id; FacadeUpdateResult <FolderData> subResult = SaveFolderTree(subFolder); parentFolderResult.ValidationResult.Merge(subResult.ValidationResult); } } return(parentFolderResult); }