private bool DeletePartialViewMacro(string path, PartialViewType partialViewType, int userId = 0) { using (var scope = ScopeProvider.CreateScope()) { var repository = GetPartialViewRepository(partialViewType); var partialView = repository.Get(path); if (partialView == null) { scope.Complete(); return(true); } var deleteEventArgs = new DeleteEventArgs <IPartialView>(partialView); if (scope.Events.DispatchCancelable(DeletingPartialView, this, deleteEventArgs)) { scope.Complete(); return(false); } repository.Delete(partialView); deleteEventArgs.CanCancel = false; scope.Events.Dispatch(DeletedPartialView, this, deleteEventArgs); Audit(AuditType.Delete, userId, -1, partialViewType.ToString()); scope.Complete(); } return(true); }
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)); }
private Attempt <IPartialView> SavePartialView(IPartialView partialView, PartialViewType partialViewType, int userId = 0) { using (var scope = ScopeProvider.CreateScope()) { var saveEventArgs = new SaveEventArgs <IPartialView>(partialView); if (scope.Events.DispatchCancelable(SavingPartialView, this, saveEventArgs)) { scope.Complete(); return(Attempt <IPartialView> .Fail()); } var repository = GetPartialViewRepository(partialViewType); repository.Save(partialView); saveEventArgs.CanCancel = false; Audit(AuditType.Save, userId, -1, partialViewType.ToString()); scope.Events.Dispatch(SavedPartialView, this, saveEventArgs); scope.Complete(); } return(Attempt.Succeed(partialView)); }
private Attempt <IPartialView> CreatePartialViewMacro(IPartialView partialView, PartialViewType partialViewType, string snippetName = null, int userId = 0) { 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 var 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); partialViewContent = $"{partialViewHeader}{Environment.NewLine}{snippetContent}"; } } using (var scope = ScopeProvider.CreateScope()) { var newEventArgs = new NewEventArgs <IPartialView>(partialView, true, partialView.Alias, -1); if (scope.Events.DispatchCancelable(CreatingPartialView, this, newEventArgs)) { scope.Complete(); return(Attempt <IPartialView> .Fail()); } var repository = GetPartialViewRepository(partialViewType); if (partialViewContent != null) { partialView.Content = partialViewContent; } repository.Save(partialView); newEventArgs.CanCancel = false; scope.Events.Dispatch(CreatedPartialView, this, newEventArgs); Audit(AuditType.Save, userId, -1, partialViewType.ToString()); scope.Complete(); } return(Attempt <IPartialView> .Succeed(partialView)); }
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)); }