public Attempt <OperationResult <OperationResultType, EntityContainer> > CreateContainer(int parentId, string name, int userId = Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); using (var scope = ScopeProvider.CreateScope()) { try { var container = new EntityContainer(Constants.ObjectTypes.DataType) { Name = name, ParentId = parentId, CreatorId = userId }; if (scope.Events.DispatchCancelable(SavingContainer, this, new SaveEventArgs <EntityContainer>(container, evtMsgs))) { scope.Complete(); return(OperationResult.Attempt.Cancel(evtMsgs, container)); } _dataTypeContainerRepository.Save(container); scope.Complete(); scope.Events.Dispatch(SavedContainer, this, new SaveEventArgs <EntityContainer>(container, evtMsgs)); // TODO: Audit trail ? return(OperationResult.Attempt.Succeed(evtMsgs, container)); } catch (Exception ex) { return(OperationResult.Attempt.Fail <EntityContainer>(evtMsgs, ex)); } } }
public Attempt <OperationResult <OperationResultType, EntityContainer> > CreateContainer(int parentId, Guid key, string name, int userId = Cms.Core.Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); using (var scope = ScopeProvider.CreateScope()) { try { var container = new EntityContainer(Cms.Core.Constants.ObjectTypes.DataType) { Name = name, ParentId = parentId, CreatorId = userId, Key = key }; var savingEntityContainerNotification = new EntityContainerSavingNotification(container, evtMsgs); if (scope.Notifications.PublishCancelable(savingEntityContainerNotification)) { scope.Complete(); return(OperationResult.Attempt.Cancel(evtMsgs, container)); } _dataTypeContainerRepository.Save(container); scope.Complete(); scope.Notifications.Publish(new EntityContainerSavedNotification(container, evtMsgs).WithStateFrom(savingEntityContainerNotification)); // TODO: Audit trail ? return(OperationResult.Attempt.Succeed(evtMsgs, container)); } catch (Exception ex) { return(OperationResult.Attempt.Fail <EntityContainer>(evtMsgs, ex)); } } }