/*========================================================================================================================== | HELPER: SAVE TO TOPIC \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Adds the form values to a new <see cref="Topic"/>, and saves it to the <see cref="ITopicRepository"/>. /// </summary> private async Task SaveToTopic(ITopicBindingModel bindingModel) { /*------------------------------------------------------------------------------------------------------------------------ | Establish variables \-----------------------------------------------------------------------------------------------------------------------*/ bindingModel.ContentType = bindingModel.GetType().Name.Replace("BindingModel", ""); bindingModel.Key = bindingModel.ContentType + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"); /*------------------------------------------------------------------------------------------------------------------------ | Validate Topic Parent \-----------------------------------------------------------------------------------------------------------------------*/ var parentKey = "Administration:Licenses"; var parentTopic = TopicRepository.Load(parentKey); /*------------------------------------------------------------------------------------------------------------------------ | Map binding model to new topic \-----------------------------------------------------------------------------------------------------------------------*/ var topic = await _reverseMappingService.MapAsync(bindingModel); var errorMessage = $"The topic '{parentKey}' could not be found. A root topic to store forms to is required."; /*------------------------------------------------------------------------------------------------------------------------ | Set Topic values \-----------------------------------------------------------------------------------------------------------------------*/ topic.Parent = parentTopic?? throw new Exception(errorMessage); topic.LastModified = DateTime.Now; /*------------------------------------------------------------------------------------------------------------------------ | Save form Topic \-----------------------------------------------------------------------------------------------------------------------*/ TopicRepository.Save(topic); }
/*========================================================================================================================== | METHOD: INVOKE (ASYNC) \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Provides the footer menu for the site. /// </summary> public async Task<IViewComponentResult> InvokeAsync() { /*------------------------------------------------------------------------------------------------------------------------ | Establish variables \-----------------------------------------------------------------------------------------------------------------------*/ var navigationRootTopic = TopicRepository.Load("Web:Company"); var webPath = CurrentTopic?.GetWebPath(); var isInWeb = CurrentTopic?.GetUniqueKey().StartsWith("Root:Web", StringComparison.OrdinalIgnoreCase); var navigationRoot = CurrentTopic?.Attributes.GetValue("NavigationRoot", null, true); /*------------------------------------------------------------------------------------------------------------------------ | Construct view model \-----------------------------------------------------------------------------------------------------------------------*/ var navigationViewModel = new FooterViewModel() { NavigationRoot = await HierarchicalTopicMappingService.GetRootViewModelAsync(navigationRootTopic).ConfigureAwait(true), CurrentWebPath = webPath, IsMainSite = navigationRoot?.Equals("Web", StringComparison.OrdinalIgnoreCase)?? isInWeb?? true }; /*------------------------------------------------------------------------------------------------------------------------ | Return the corresponding view \-----------------------------------------------------------------------------------------------------------------------*/ return View(navigationViewModel); }
public IActionResult Delete(int[] topics) { /*------------------------------------------------------------------------------------------------------------------------ | Validate input \-----------------------------------------------------------------------------------------------------------------------*/ Contract.Requires(topics, nameof(topics)); /*------------------------------------------------------------------------------------------------------------------------ | Delete topics \-----------------------------------------------------------------------------------------------------------------------*/ foreach (var topicId in topics) { if (topicId < 0) { continue; } var topic = TopicRepository.Load(topicId); if (!topic.GetUniqueKey().StartsWith(_licenseRoot, StringComparison.InvariantCultureIgnoreCase)) { continue; } TopicRepository.Delete(topic); } /*------------------------------------------------------------------------------------------------------------------------ | Return default view \-----------------------------------------------------------------------------------------------------------------------*/ return RedirectToAction(nameof(Index)); }
/*========================================================================================================================== | METHOD: GET NAVIGATION ROOT \-------------------------------------------------------------------------------------------------------------------------*/ /// <inheritdoc /> /// <summary> /// Retrieves the root <see cref="Topic"/> from which to map the <typeparamref name="T"/> objects. /// </summary> /// <remarks> /// The navigation root in the case of the main menu is the namespace; i.e., the first topic underneath the root. /// </remarks> protected Topic? GetNavigationRoot() { /*------------------------------------------------------------------------------------------------------------------------ | Validate dependencies \-----------------------------------------------------------------------------------------------------------------------*/ Contract.Assume(CurrentTopic, nameof(CurrentTopic)); /*------------------------------------------------------------------------------------------------------------------------ | Identify navigation root \-----------------------------------------------------------------------------------------------------------------------*/ var navigationRootTopic = (Topic?)null; var configuredRoot = CurrentTopic.Attributes.GetValue("NavigationRoot", true); if (!String.IsNullOrEmpty(configuredRoot)) { navigationRootTopic = TopicRepository.Load(configuredRoot); } if (navigationRootTopic is null) { navigationRootTopic = HierarchicalTopicMappingService.GetHierarchicalRoot(CurrentTopic, 2, "Web"); } /*------------------------------------------------------------------------------------------------------------------------ | Return root \-----------------------------------------------------------------------------------------------------------------------*/ return navigationRootTopic; }
public IActionResult VerifyEmail([Bind(Prefix="BindingModel.Email")] string email) { if (String.IsNullOrWhiteSpace(email)) return Json(data: true); var domains = TopicRepository.Load("Root:Configuration:Metadata:GenericEmailDomains:LookupList").Children; var invalidDomain = domains?.FirstOrDefault(m => email.Contains(m.Title, StringComparison.InvariantCultureIgnoreCase)); if (invalidDomain != null) { return Json($"Please use an email address with an institutional domain; '@{invalidDomain.Title}' is not valid."); } return Json(data: true); }
public FileStreamResult Export() { /*------------------------------------------------------------------------------------------------------------------------ | Establish variables \-----------------------------------------------------------------------------------------------------------------------*/ var licenseRequestContainer = TopicRepository.Load(_licenseRoot)?.Children; var validContentTypes = new string[] { "TrialForm", "InstructorAcademicForm", "StudentAcademicForm"}; var licenseRequests = licenseRequestContainer.Where(topic => validContentTypes.Contains(topic.ContentType)); var memoryStream = _topicExportService.Export(licenseRequests); /*------------------------------------------------------------------------------------------------------------------------ | Return the Excel spreadsheet as a file stream \-----------------------------------------------------------------------------------------------------------------------*/ return File(memoryStream, _topicExportService.MimeType, "MultipleFreeLicenses" + _topicExportService.FileExtension); }
/*========================================================================================================================== | HELPER: SAVE TO TOPIC \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Adds the form values to a new <see cref="Topic"/>, and saves it to the <see cref="ITopicRepository"/>. /// </summary> private async Task SaveToTopic(CoreContact bindingModel) { /*------------------------------------------------------------------------------------------------------------------------ | Establish variables \-----------------------------------------------------------------------------------------------------------------------*/ var contentType = bindingModel.GetType().Name.Replace("BindingModel", "", StringComparison.Ordinal); bindingModel = bindingModel with { ContentType = contentType, Key = contentType + "_" + DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) }; /*------------------------------------------------------------------------------------------------------------------------ | Validate Topic Parent \-----------------------------------------------------------------------------------------------------------------------*/ var parentKey = "Administration:Licenses"; var parentTopic = TopicRepository.Load(parentKey); /*------------------------------------------------------------------------------------------------------------------------ | Map binding model to new topic \-----------------------------------------------------------------------------------------------------------------------*/ var topic = await _reverseMappingService.MapAsync(bindingModel).ConfigureAwait(true); var errorMessage = $"The topic '{parentKey}' could not be found. A root topic to store forms to is required."; /*------------------------------------------------------------------------------------------------------------------------ | Set Topic values \-----------------------------------------------------------------------------------------------------------------------*/ topic.Parent = parentTopic?? throw new InvalidOperationException(errorMessage); topic.LastModified = DateTime.Now; /*------------------------------------------------------------------------------------------------------------------------ | Save form Topic \-----------------------------------------------------------------------------------------------------------------------*/ TopicRepository.Save(topic); }
/*========================================================================================================================== | FUNCTION: GET INVOICE \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Given an invoice number, retrieves a corresponding topic. /// </summary> private Topic GetInvoice(int? invoiceNumber = null) { if (invoiceNumber == null) return null; var invoice = TopicRepository.Load($"Administration:Invoices:{invoiceNumber}"); return invoice; }