/// <summary> /// Gets the child content options. /// </summary> /// <param name="contentId">The content identifier.</param> /// <returns></returns> public IList <ContentOptionValuesViewModel> GetChildContentsOptionValues(Guid contentId) { var models = new List <ContentOptionValuesViewModel>(); var allChildContents = repository.AsQueryable <ChildContent>() .Where(f => f.Parent.Id == contentId && !f.IsDeleted && !f.Child.IsDeleted) .OrderBy(f => f.AssignmentIdentifier) .Fetch(f => f.Child) .ThenFetchMany(f => f.ContentOptions) .ThenFetch(f => f.CustomOption) .FetchMany(f => f.Options) .ThenFetch(f => f.CustomOption) .ToList(); foreach (var childContent in allChildContents) { var model = new ContentOptionValuesViewModel { OptionValuesContainerId = childContent.AssignmentIdentifier }; model.OptionValues = GetMergedOptionValuesForEdit(childContent.Child.ContentOptions, childContent.Options); if (model.OptionValues.Any()) { models.Add(model); } } return(models); }
public ActionResult PageContentOptions(ContentOptionValuesViewModel model) { bool success = GetCommand <SavePageContentOptionsCommand>().ExecuteCommand(model); return(Json(new WireJson { Success = success })); }
/// <summary> /// Saves the child content options.. /// </summary> /// <param name="content">The content.</param> /// <param name="viewModels">The list of view models with provided child content id and option values list.</param> /// <param name="requestedStatus">The requested status for saving content.</param> public void SaveChildContentOptions(Models.Content content, IList <ContentOptionValuesViewModel> viewModels, ContentStatus requestedStatus) { if (viewModels == null) { viewModels = new ContentOptionValuesViewModel[0]; } Models.Content contentToUdpate = null; if ((requestedStatus == ContentStatus.Draft || requestedStatus == ContentStatus.Preview) && content != null && requestedStatus != content.Status && content.History != null) { contentToUdpate = content.History.FirstOrDefault(c => c.Status == requestedStatus); } if (contentToUdpate == null) { contentToUdpate = content; } if (contentToUdpate != null && contentToUdpate.ChildContents != null) { foreach (var childContent in contentToUdpate.ChildContents) { var viewModel = viewModels.FirstOrDefault(vm => vm.OptionValuesContainerId == childContent.AssignmentIdentifier); if (viewModel == null) { continue; } IList <OptionValueEditViewModel> optionValues = viewModel.OptionValues; IList <ChildContentOption> childContentOptions = null; if (childContent.Options != null) { childContentOptions = childContent.Options.Distinct().ToList(); } SaveOptionValues(optionValues, childContentOptions, () => new ChildContentOption { ChildContent = childContent }); } } }
public ActionResult PageContentOptions(ContentOptionValuesViewModel model) { var response = GetCommand <SavePageContentOptionsCommand>().ExecuteCommand(model); return(WireJson(response != null, response)); }
public void Should_Save_Page_Content_Options_Successfully() { RunActionInTransaction(session => { // Create page content with options var content = TestDataProvider.CreateNewContent(); var pageContent = TestDataProvider.CreateNewPageContent(content); FillContentWithOptions(content); FillPageContentWithOptions(content, pageContent); session.SaveOrUpdate(pageContent); session.Flush(); session.Clear(); // Random option value var randomOptionValue = TestDataProvider.CreateNewPageContentOption(); // Create request var request = new ContentOptionValuesViewModel { OptionValues = new List <OptionValueEditViewModel> { new OptionValueEditViewModel { // Must be updated OptionKey = pageContent.Options[0].Key, OptionValue = content.ContentOptions[0].DefaultValue, UseDefaultValue = false }, new OptionValueEditViewModel { // Must be deleted OptionKey = pageContent.Options[1].Key, OptionValue = null, UseDefaultValue = true }, new OptionValueEditViewModel { // Must be updated OptionKey = pageContent.Options[2].Key, OptionValue = null, UseDefaultValue = false }, new OptionValueEditViewModel { // Must be created OptionValue = randomOptionValue.Value, OptionKey = randomOptionValue.Key, Type = OptionType.Text } }, OptionValuesContainerId = pageContent.Id }; // Create command var unitOfWork = new DefaultUnitOfWork(session); var repository = new DefaultRepository(unitOfWork); var command = new SavePageContentOptionsCommand(); command.UnitOfWork = unitOfWork; command.Repository = repository; command.OptionService = new DefaultOptionService(repository, new HttpRuntimeCacheService()); var result = command.Execute(request); Assert.IsTrue(result); // Check results: one of page content values must be deleted after save var results = repository .AsQueryable <PageContentOption>(pco => pco.PageContent.Id == pageContent.Id && !pco.IsDeleted && !pco.PageContent.IsDeleted) .ToList(); Assert.AreEqual(results.Count, 3); Assert.IsNotNull(results.FirstOrDefault(pco => { return(pco.Key == pageContent.Options[0].Key && pco.Value == content.ContentOptions[0].DefaultValue); })); Assert.IsNotNull(results.FirstOrDefault(pco => { return(pco.Key == pageContent.Options[2].Key && pco.Value == null); })); Assert.IsNotNull(results.FirstOrDefault(pco => pco.Key == randomOptionValue.Key && pco.Value == randomOptionValue.Value)); }); }