private bool DeletePartialViewMacro(string path, PartialViewType partialViewType, int?userId = null) { using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { IPartialViewRepository repository = GetPartialViewRepository(partialViewType); IPartialView? partialView = repository.Get(path); if (partialView == null) { scope.Complete(); return(true); } EventMessages eventMessages = EventMessagesFactory.Get(); var deletingNotification = new PartialViewDeletingNotification(partialView, eventMessages); if (scope.Notifications.PublishCancelable(deletingNotification)) { scope.Complete(); return(false); } userId ??= Constants.Security.SuperUserId; repository.Delete(partialView); scope.Notifications.Publish(new PartialViewDeletedNotification(partialView, eventMessages).WithStateFrom(deletingNotification)); Audit(AuditType.Delete, userId.Value, -1, partialViewType.ToString()); scope.Complete(); } return(true); }
private Attempt <IPartialView?> SavePartialView(IPartialView partialView, PartialViewType partialViewType, int?userId = null) { using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new PartialViewSavingNotification(partialView, eventMessages); if (scope.Notifications.PublishCancelable(savingNotification)) { scope.Complete(); return(Attempt <IPartialView?> .Fail()); } userId ??= Constants.Security.SuperUserId; IPartialViewRepository repository = GetPartialViewRepository(partialViewType); repository.Save(partialView); Audit(AuditType.Save, userId.Value, -1, partialViewType.ToString()); scope.Notifications.Publish( new PartialViewSavedNotification(partialView, eventMessages).WithStateFrom(savingNotification)); scope.Complete(); } return(Attempt.Succeed(partialView)); }
public FileService( ICoreScopeProvider uowProvider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IStylesheetRepository stylesheetRepository, IScriptRepository scriptRepository, ITemplateRepository templateRepository, IPartialViewRepository partialViewRepository, IPartialViewMacroRepository partialViewMacroRepository, IAuditRepository auditRepository, IShortStringHelper shortStringHelper, IOptions <GlobalSettings> globalSettings, IHostingEnvironment hostingEnvironment) : base(uowProvider, loggerFactory, eventMessagesFactory) { _stylesheetRepository = stylesheetRepository; _scriptRepository = scriptRepository; _templateRepository = templateRepository; _partialViewRepository = partialViewRepository; _partialViewMacroRepository = partialViewMacroRepository; _auditRepository = auditRepository; _shortStringHelper = shortStringHelper; _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; }
public FileService(IScopeProvider uowProvider, ILogger logger, IEventMessagesFactory eventMessagesFactory, IStylesheetRepository stylesheetRepository, IScriptRepository scriptRepository, ITemplateRepository templateRepository, IPartialViewRepository partialViewRepository, IPartialViewMacroRepository partialViewMacroRepository, IAuditRepository auditRepository) : base(uowProvider, logger, eventMessagesFactory) { _stylesheetRepository = stylesheetRepository; _scriptRepository = scriptRepository; _templateRepository = templateRepository; _partialViewRepository = partialViewRepository; _partialViewMacroRepository = partialViewMacroRepository; _auditRepository = auditRepository; }
private Attempt <IPartialView?> CreatePartialViewMacro(IPartialView partialView, PartialViewType partialViewType, string?snippetName = null, int?userId = Constants.Security.SuperUserId) { string partialViewHeader; switch (partialViewType) { case PartialViewType.PartialView: partialViewHeader = PartialViewHeader; break; case PartialViewType.PartialViewMacro: partialViewHeader = PartialViewMacroHeader; break; default: throw new ArgumentOutOfRangeException(nameof(partialViewType)); } string?partialViewContent = null; if (snippetName.IsNullOrWhiteSpace() == false) { //create the file Attempt <string> snippetPathAttempt = TryGetSnippetPath(snippetName); if (snippetPathAttempt.Success == false) { throw new InvalidOperationException("Could not load snippet with name " + snippetName); } using (var snippetFile = new StreamReader(System.IO.File.OpenRead(snippetPathAttempt.Result !))) { var snippetContent = snippetFile.ReadToEnd().Trim(); //strip the @inherits if it's there snippetContent = StripPartialViewHeader(snippetContent); //Update Model.Content. to be Model. when used as PartialView if (partialViewType == PartialViewType.PartialView) { snippetContent = snippetContent.Replace("Model.Content.", "Model."); } partialViewContent = $"{partialViewHeader}{Environment.NewLine}{snippetContent}"; } } using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var creatingNotification = new PartialViewCreatingNotification(partialView, eventMessages); if (scope.Notifications.PublishCancelable(creatingNotification)) { scope.Complete(); return(Attempt <IPartialView?> .Fail()); } IPartialViewRepository repository = GetPartialViewRepository(partialViewType); if (partialViewContent != null) { partialView.Content = partialViewContent; } repository.Save(partialView); scope.Notifications.Publish(new PartialViewCreatedNotification(partialView, eventMessages).WithStateFrom(creatingNotification)); Audit(AuditType.Save, userId !.Value, -1, partialViewType.ToString()); scope.Complete(); } return(Attempt <IPartialView?> .Succeed(partialView)); }