protected override IEnumerable<IDataParameter> CoreGetColumnParameters(IUnitOfWorkContext unitOfWorkContext, string dataSourceTag, Database database, Schema schema, Table table) { if ((object)unitOfWorkContext == null) throw new ArgumentNullException("unitOfWorkContext"); if ((object)dataSourceTag == null) throw new ArgumentNullException("dataSourceTag"); if ((object)database == null) throw new ArgumentNullException("database"); if ((object)schema == null) throw new ArgumentNullException("schema"); if ((object)table == null) throw new ArgumentNullException("table"); if (dataSourceTag.SafeToString().ToLower() == "net.sqlserver" || dataSourceTag.SafeToString().ToLower() == "net.sqlce") { return new IDataParameter[] { unitOfWorkContext.CreateParameter(ParameterDirection.Input, DbType.String, 100, 0, 0, true, "@SchemaName", schema.SchemaName), unitOfWorkContext.CreateParameter(ParameterDirection.Input, DbType.String, 100, 0, 0, true, "@TableOrViewName", table.TableName) }; } throw new ArgumentOutOfRangeException(string.Format("dataSourceTag: '{0}'", dataSourceTag)); }
private static IMessagingAggregateRoot GetReceiver(IUnitOfWorkContext work, IncomingMessage message) { var existingReceiver = (IMessagingAggregateRoot)work.GetById(message.ReceiverType, message.ReceiverId, null); CheckProcessingRequirements(message, existingReceiver); return existingReceiver ?? CreateNewAggregateInstance(message.ReceiverType, message.ReceiverId); }
public UnitOfWork(IClientOutboxStorageV2 clientOutboxStorage, IMessageSession messageSession, IUnitOfWorkContext unitOfWorkContext, ReadOnlySettings settings) { _clientOutboxStorage = clientOutboxStorage; _messageSession = messageSession; _unitOfWorkContext = unitOfWorkContext; _settings = settings; }
private IDeviceRepository deviceRepository; // 设备管理 public BaseSystemConfigService(IUnitOfWorkContext unitContext, IDataDictRepository DataDictRepository, IFieldTypeRepository FieldTypeRepository, IDeviceRepository DeviceRepository) : base(unitContext) { this.fieldTypeRepository = FieldTypeRepository; this.dataDictRepository = DataDictRepository; this.deviceRepository = DeviceRepository; }
protected override void ExecuteInContext(IUnitOfWorkContext context, InvalidateUserCommand command) { var aggregate = context.GetById <User>(command.UserID) as User; aggregate.Invalidate(command.UserID); context.Accept(); }
protected override void ExecuteInContext(IUnitOfWorkContext context, AddInvoiceDiscount command) { Invoice invoice = context.GetById <Invoice>(command.InvoiceId, command.KnownVersion); invoice.GiveDiscount(command.DiscountInPercent); context.Accept(); }
/// <summary> /// Create proxy for unit-of-work. /// </summary> /// <param name="unitOfWorkContext">Unit-of-work context.</param> public UnitOfWorkProvider(IUnitOfWorkContext unitOfWorkContext) { if (unitOfWorkContext == null) { throw new UnitOfWorkException($"Cannot get active {nameof(IUnitOfWork)}: {nameof(unitOfWorkContext)} is not assigned"); } if (unitOfWorkContext.CurrentUnitOfWork != null) { this.unitOfWork = unitOfWorkContext.CurrentUnitOfWork; this.isCurrent = true; } else { if (unitOfWorkContext.Factory == null) { throw new UnitOfWorkException($"Cannot create new {nameof(IUnitOfWork)}: {nameof(unitOfWorkContext.Factory)} is not assigned"); } this.unitOfWork = unitOfWorkContext.Factory.Create(); this.isCurrent = false; if (this.unitOfWork == null) { throw new UnitOfWorkException($"Cannot use {nameof(UnitOfWorkProvider)}: {nameof(unitOfWorkContext.Factory)} returned null value of {nameof(IUnitOfWork)}"); } } }
public UnitOfWorkManager(IDb db, IMessageSession messageSession, IUnitOfWorkContext unitOfWorkContext, IOutbox outbox, ReadOnlySettings settings) { _db = db; _messageSession = messageSession; _unitOfWorkContext = unitOfWorkContext; _outbox = outbox; _settings = settings; }
protected override void ExecuteInContext(IUnitOfWorkContext context, SetUserPropertyCommand command) { var aggregate = context.GetById <User>(command.UserID) as User; aggregate.SetProperty(command.UserID, command.Name, command.Value); context.Accept(); }
private static IMessagingAggregateRoot GetReceiver(IUnitOfWorkContext work, IncomingMessage message) { var existingReceiver = (IMessagingAggregateRoot)work.GetById(message.ReceiverType, message.ReceiverId, null); CheckProcessingRequirements(message, existingReceiver); return(existingReceiver ?? CreateNewAggregateInstance(message.ReceiverType, message.ReceiverId)); }
protected override void ExecuteInContext(IUnitOfWorkContext context, DeleteTweetCommand command) { var aggregate = context.GetById <Tweet>(command.TweetID) as Tweet; aggregate.Delete(command.TweetID); context.Accept(); }
protected override void ExecuteInContext(IUnitOfWorkContext context, AddUserToRoleCommand command) { var aggregate = context.GetById <User>(command.UserID) as User; aggregate.AddToRole(command.UserID, command.Role); context.Accept(); }
protected override void ExecuteInContext(IUnitOfWorkContext context, SetUserPasswordCommand command) { var aggregate = context.GetById <User>(command.UserID) as User; aggregate.SetPassword(command.UserID, command.Password); context.Accept(); }
protected UnitOfWork(IUnitOfWorkContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } Context = context; }
/// <summary> /// Constructor, initializes a new instance of <see cref="MappedCommandToAggregateRootMethod<TCommand, TAggRoot>"/>. /// </summary> /// <param name="getidfromcommandfunc">The method responsible for retrieving the id of the aggregateroot from the command.</param> /// <remarks>Marked as internal because the construction is only allowed in the framework.</remarks> internal MappedCommandToAggregateRootMethod(Func <TCommand, Guid> getidfromcommandfunc) { _getidfromcommandfunc = getidfromcommandfunc; _aggregaterootfetchfunc = delegate(Guid guid, long?lastKnownVersion) { IUnitOfWorkContext uow = UnitOfWorkContext.Current; return((TAggRoot)uow.GetById(typeof(TAggRoot), guid, lastKnownVersion)); }; }
public DeleteReservationCommandHandler( IValidator <DeleteReservationCommand> validator, IAccountReservationService reservationService, IUnitOfWorkContext context) { _validator = validator; _reservationService = reservationService; _context = context; }
/// <summary> /// /// </summary> /// <param name="workContext"></param> public EFRepository(IUnitOfWorkContext workContext = null) { if (workContext == null) { workContext = UnitOfWorkContextManage.WorkContext(); } // _workContext = workContext; }
public BaseAuthorityService(IUnitOfWorkContext unitContext, IUserRepository UserRepository, IRoleRepository RoleRepository, IModuleRepository ModuleRepository, IRoleModuleRepository RoleModuleRepository, ILogRepository LogRepository) : base(unitContext) { this.userRepository = UserRepository; this.roleRepository = RoleRepository; this.moduleRepository = ModuleRepository; this.roleModuleRepository = RoleModuleRepository; }
protected override void ExecuteInContext(IUnitOfWorkContext context, AddInvoiceItem command) { ITaxRepository taxRepo = NcqrsEnvironment.Get <ITaxRepository>(); Tax tax = taxRepo.FindByCode(command.TaxCode, command.OwnerId); Invoice invoice = context.GetById <Invoice>(command.InvoiceId, command.KnownVersion); invoice.AddInvoiceItem(command.ItemId, command.Description, command.Quantity, command.Price, command.DiscountInPercent, tax, command.OwnerId, command.UserName); context.Accept(); }
public CreateAccountReservationCommandHandler(IAccountReservationService accountReservationService, IValidator <CreateAccountReservationCommand> validator, IGlobalRulesService globalRulesService, IUnitOfWorkContext context, IAccountLegalEntitiesService accountLegalEntitiesService) { _accountReservationService = accountReservationService; _validator = validator; _globalRulesService = globalRulesService; _context = context; _accountLegalEntitiesService = accountLegalEntitiesService; }
partial void OnPreInsertEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog eventLog) { if ((object)unitOfWorkContext == null) throw new ArgumentNullException("unitOfWorkContext"); if ((object)eventLog == null) throw new ArgumentNullException("eventLog"); //eventLog.Mark(); }
partial void OnPreInsertEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage emailMessage) { if ((object)unitOfWorkContext == null) throw new ArgumentNullException("unitOfWorkContext"); if ((object)emailMessage == null) throw new ArgumentNullException("emailMessage"); //emailMessage.Mark(); }
partial void OnPreInsertEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment emailAttachment) { if ((object)unitOfWorkContext == null) throw new ArgumentNullException("unitOfWorkContext"); if ((object)emailAttachment == null) throw new ArgumentNullException("emailAttachment"); //emailAttachment.Mark(); }
} // 出库管理业务 /// <summary> /// 参数形式初始化仓储类 /// </summary> /// <param name="unitContext">上下文</param> /// <param name="arvRepository">档案管理</param> /// <param name="arvBoxRepository">档案盒管理</param> /// <param name="lendRepository">借阅管理</param> /// <param name="returnRepository">归还管理</param> /// <param name="outCabRepository">出库管理</param> public BaseArvOpService(IUnitOfWorkContext unitContext, IArvRepository arvRepository, IArvBoxRepository arvBoxRepository, ILendRepository lendRepository, IReturnRepository returnRepository, IArvLendReturnRepository arvLendReturnRepository, IOutCabRepository outCabRepository) : base(unitContext) { this.arvRepository = arvRepository; this.arvBoxRepository = arvBoxRepository; this.lendRepository = lendRepository; this.returnRepository = returnRepository; this.outCabRepository = outCabRepository; this.arvLendReturnRepository = arvLendReturnRepository; }
/// <summary> /// Starts the unit of work. /// </summary> /// <returns>New unit of work.</returns> public static IUnitOfWork StartUnitOfWork(IUnitOfWorkContext innerContext = null) { var unitOfWork = FactoryResolver.GetUnitOfWork(); if (innerContext != null) { unitOfWork.InitUnitOfWorkContext(innerContext); } return(unitOfWork); }
/// <summary> /// 参数化构造函数 /// </summary> /// <param name="context">DbContext对象</param> public BaseRepository(IUnitOfWorkContext unitContext) { if (unitContext is IEFUnitOfWorkContext) { this.EFContext = unitContext as IEFUnitOfWorkContext; } this.IsDescending = true; // 默认降序 this.SortPropertyName = "ID"; // 排序依据为“ID” }
public void Arrange() { _employerAccountRepository = new Mock <IEmployerAccountRepository>(); _transferConnectionInvitationRepository = new Mock <ITransferConnectionInvitationRepository>(); _userRepository = new Mock <IUserAccountRepository>(); _receiverUser = new User { Id = 123456, Ref = Guid.NewGuid(), FirstName = "John", LastName = "Doe" }; _senderAccount = new Account { Id = 333333, HashedId = "ABC123", Name = "Sender" }; _receiverAccount = new Account { Id = 222222, HashedId = "XYZ987", Name = "Receiver" }; _unitOfWorkContext = new UnitOfWorkContext(); _transferConnectionInvitation = new TransferConnectionInvitationBuilder() .WithId(111111) .WithSenderAccount(_senderAccount) .WithReceiverAccount(_receiverAccount) .WithStatus(TransferConnectionInvitationStatus.Pending) .Build(); _userRepository.Setup(r => r.GetUserByRef(_receiverUser.Ref)).ReturnsAsync(_receiverUser); _employerAccountRepository.Setup(r => r.GetAccountById(_senderAccount.Id)).ReturnsAsync(_senderAccount); _employerAccountRepository.Setup(r => r.GetAccountById(_receiverAccount.Id)).ReturnsAsync(_receiverAccount); _transferConnectionInvitationRepository.Setup(r => r.GetTransferConnectionInvitationById(_transferConnectionInvitation.Id)).ReturnsAsync(_transferConnectionInvitation); _handler = new ApproveTransferConnectionInvitationCommandHandler( _employerAccountRepository.Object, _transferConnectionInvitationRepository.Object, _userRepository.Object ); _command = new ApproveTransferConnectionInvitationCommand { AccountId = _receiverAccount.Id, UserRef = _receiverUser.Ref, TransferConnectionInvitationId = _transferConnectionInvitation.Id }; }
public Sender(NServiceBusConfiguration nServiceBusConfig, IEndpointInstance endpointInstance, IEventPublisher publisher, IUnitOfWorkContext unitOfWorkContext) //, ILog log) { //_log = log; _nServiceBusConfig = nServiceBusConfig; Publisher = publisher; EndpointInstance = endpointInstance; _unitOfWorkContext = unitOfWorkContext; }
protected override void ExecuteInContext(IUnitOfWorkContext context, ValidateUserCommand command) { var aggregate = context.GetById <User>(command.UserID) as User; bool validated = aggregate.Validate(command.UserID, command.Username, command.Password); if (validated) { aggregate.Validated(command.UserID); context.Accept(); } }
/// <summary> /// Constructor, initializes a new instance of <see cref="MappedCommandToAggregateRootMethodOrConstructor<TCommand, TAggRoot>"/>. /// </summary> /// <param name="getidfromcommandfunc">The method responsible for retrieving the id of the aggregateroot from the command.</param> /// <param name="creatorfunc">The method that is responsible for the creation of the aggregateroot.</param> /// <remarks>Marked as internal because the construction is only allowed in the framework.</remarks> internal MappedCommandToAggregateRootMethodOrConstructor(Func <TCommand, Guid> getidfromcommandfunc, Func <TCommand, TAggRoot> creatorfunc) { Contract.Requires <ArgumentNullException>(creatorfunc != null, "creatorfunc can not be null."); _aggregaterootcreatorfunc = creatorfunc; _getidfromcommandfunc = getidfromcommandfunc; _aggregaterootfetchfunc = delegate(Guid guid, long?lastKnownVersion) { IUnitOfWorkContext uow = UnitOfWorkContext.Current; return((TAggRoot)uow.GetById(typeof(TAggRoot), guid, lastKnownVersion)); }; }
/// <summary> /// Initializes a new instance of the <see cref="UnitOfWork" /> class. /// </summary> /// <param name="provider">The provider.</param> /// <param name="loader">The loader.</param> /// <param name="aggregateEventContext">The aggregate event context.</param> /// <param name="workContext">The context.</param> /// <param name="queueSender">The queue sender.</param> public UnitOfWork( IPersistenceProvider provider, IAggregateLoader loader, IAggregateEventContext aggregateEventContext, IUnitOfWorkContext workContext, IUnitOfWorkQueueSender queueSender) { this.provider = Check.NotNull(() => provider); this.loader = Check.NotNull(() => loader); this.aggregateEventContext = Check.NotNull(() => aggregateEventContext); this.workContext = Check.NotNull(() => workContext); this.queueSender = Check.NotNull(() => queueSender); this.Clean(); }
public SqlExpressionVisitor(IDataSourceTagSpecific dataSourceTagSpecific, IUnitOfWorkContext unitOfWorkContext, IList<IDataParameter> commandParameters) { if ((object)dataSourceTagSpecific == null) throw new ArgumentNullException("dataSourceTagSpecific"); if ((object)unitOfWorkContext == null) throw new ArgumentNullException("unitOfWorkContext"); if ((object)commandParameters == null) throw new ArgumentNullException("commandParameters"); this.dataSourceTagSpecific = dataSourceTagSpecific; this.unitOfWorkContext = unitOfWorkContext; this.commandParameters = commandParameters; }
public async Task <IActionResult> Test2(IUnitOfWorkContext context, League league) { // Transaction Scope return(await context.Run(async transaction => { // Command Scope return await transaction.Run(async command => { // Atomic Commands return await command.Post(league); }); // Convert to an IActionResult (handle Exceptions) }).Handle <IActionResult, League>(s => new CreatedResult(s.Id.ToString(), s), e => new BadRequestObjectResult(e))); }
public AddAccountProviderCommandHandlerTestsFixture() { Db = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options); Account = EntityActivator.CreateInstance <Account>().Set(a => a.Id, 1); User = EntityActivator.CreateInstance <User>().Set(u => u.Ref, Guid.NewGuid()); Provider = EntityActivator.CreateInstance <Provider>().Set(p => p.Ukprn, 12345678); Db.Accounts.Add(Account); Db.Users.Add(User); Db.Providers.Add(Provider); Db.SaveChanges(); Command = new AddAccountProviderCommand(Account.Id, Provider.Ukprn, User.Ref); Now = DateTime.UtcNow; UnitOfWorkContext = new UnitOfWorkContext(); Handler = new AddAccountProviderCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db)); }
public bool DiscardEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment) { TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EmailAttachment query; if ((object)unitOfWorkContext == null) throw new ArgumentNullException("unitOfWorkContext"); if ((object)@emailAttachment == null) throw new ArgumentNullException("emailAttachment"); if (@emailAttachment.IsNew) return true; using (ContextWrapper<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext> ctx = unitOfWorkContext.GetContext<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext>()) { this.OnPreDeleteEmailAttachment(unitOfWorkContext, @emailAttachment); query = [email protected](lo => lo.@EmailAttachmentId == @emailAttachment.@EmailAttachmentId); if((object)query == null) throw new InvalidOperationException("TODO (enhancement): add meaningful message"); [email protected](query); try { ctx.Context.SubmitChanges(ConflictMode.FailOnFirstConflict); } catch (ChangeConflictException ccex) { this.OnDiscardConflictEmailAttachment(unitOfWorkContext, @emailAttachment); return false; } this.OnPostDeleteEmailAttachment(unitOfWorkContext, @emailAttachment); @emailAttachment.IsNew = false; return true; } }
/// <summary> /// Create new unit-of-work scope. /// </summary> /// <param name="dbContextFactory">Factory that creates database context.</param> /// <param name="unitOfWorkContext">Unit-of-work context.</param> public UnitOfWorkScope(IDbContextFactory dbContextFactory, IUnitOfWorkContext unitOfWorkContext) { // TODO: Allow wrapping UnitOfWorkScopes if (UnitOfWorkScope.Current != null) { throw new UnitOfWorkException($"Cannot create new {nameof(UnitOfWorkScope)}: outer {nameof(UnitOfWorkScope)} already exists and wrapping {nameof(UnitOfWorkScope)}s is not allowed"); } if (dbContextFactory == null) { throw new UnitOfWorkException($"Cannot create new {nameof(IDbContext)}: {nameof(dbContextFactory)} is not assigned"); } if (unitOfWorkContext == null) { throw new UnitOfWorkException($"Cannot create new {nameof(IDbContext)}: {nameof(unitOfWorkContext)} is not assigned"); } this.dbContext = dbContextFactory.Create(); this.unitOfWorkContext = unitOfWorkContext; UnitOfWorkScope.current.Value = this; }
partial void OnSaveConflictEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
partial void OnSaveConflictEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
public bool SaveEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog) { TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EventLog query; bool wasNew; if ((object)unitOfWorkContext == null) throw new ArgumentNullException("unitOfWorkContext"); if ((object)@eventLog == null) throw new ArgumentNullException("eventLog"); using (ContextWrapper<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext> ctx = unitOfWorkContext.GetContext<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext>()) { wasNew = @eventLog.IsNew; if (wasNew) { this.OnPreInsertEventLog(unitOfWorkContext, @eventLog); query = new TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EventLog(); ctx.Context.EventLogs.InsertOnSubmit(query); } else { this.OnPreUpdateEventLog(unitOfWorkContext, @eventLog); query = ctx.Context.EventLogs.SingleOrDefault(lo => lo.@EventLogId == @eventLog.@EventLogId); if((object)query == null) throw new InvalidOperationException("TODO (enhancement): add meaningful message"); } // map caller POCO changes to L2S object query.@EventLogId = @eventLog.@EventLogId; query.@EventText = @eventLog.@EventText; query.@CreationTimestamp = @eventLog.@CreationTimestamp; query.@ModificationTimestamp = @eventLog.@ModificationTimestamp; query.@LogicalDelete = @eventLog.@LogicalDelete; try { ctx.Context.SubmitChanges(ConflictMode.FailOnFirstConflict); } catch (ChangeConflictException ccex) { this.OnSaveConflictEventLog(unitOfWorkContext, @eventLog); return false; } // map server changes back to POCO from L2S object @eventLog.@EventLogId = query.@EventLogId; @eventLog.@EventText = query.@EventText; @eventLog.@CreationTimestamp = query.@CreationTimestamp; @eventLog.@ModificationTimestamp = query.@ModificationTimestamp; @eventLog.@LogicalDelete = query.@LogicalDelete; if (wasNew) { this.OnPostInsertEventLog(unitOfWorkContext, @eventLog); } else { this.OnPostUpdateEventLog(unitOfWorkContext, @eventLog); } return true; } }
public bool SaveEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment) { TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EmailAttachment query; bool wasNew; if ((object)unitOfWorkContext == null) throw new ArgumentNullException("unitOfWorkContext"); if ((object)@emailAttachment == null) throw new ArgumentNullException("emailAttachment"); using (ContextWrapper<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext> ctx = unitOfWorkContext.GetContext<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext>()) { wasNew = @emailAttachment.IsNew; if (wasNew) { this.OnPreInsertEmailAttachment(unitOfWorkContext, @emailAttachment); query = new TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EmailAttachment(); ctx.Context.EmailAttachments.InsertOnSubmit(query); } else { this.OnPreUpdateEmailAttachment(unitOfWorkContext, @emailAttachment); query = ctx.Context.EmailAttachments.SingleOrDefault(lo => lo.@EmailAttachmentId == @emailAttachment.@EmailAttachmentId); if((object)query == null) throw new InvalidOperationException("TODO (enhancement): add meaningful message"); } // map caller POCO changes to L2S object query.@EmailAttachmentId = @emailAttachment.@EmailAttachmentId; query.@EmailMessageId = @emailAttachment.@EmailMessageId; query.@MimeType = @emailAttachment.@MimeType; if ((object)@emailAttachment.@AttachmentBits != null) // prevent implicit conversion of null -> exception query.@AttachmentBits = @emailAttachment.@AttachmentBits; query.@CreationTimestamp = @emailAttachment.@CreationTimestamp; query.@ModificationTimestamp = @emailAttachment.@ModificationTimestamp; query.@LogicalDelete = @emailAttachment.@LogicalDelete; try { ctx.Context.SubmitChanges(ConflictMode.FailOnFirstConflict); } catch (ChangeConflictException ccex) { this.OnSaveConflictEmailAttachment(unitOfWorkContext, @emailAttachment); return false; } // map server changes back to POCO from L2S object @emailAttachment.@EmailAttachmentId = query.@EmailAttachmentId; @emailAttachment.@EmailMessageId = query.@EmailMessageId; @emailAttachment.@MimeType = query.@MimeType; @emailAttachment.@AttachmentBits = (object)query.@AttachmentBits != null ? [email protected]() : null; @emailAttachment.@CreationTimestamp = query.@CreationTimestamp; @emailAttachment.@ModificationTimestamp = query.@ModificationTimestamp; @emailAttachment.@LogicalDelete = query.@LogicalDelete; if (wasNew) { this.OnPostInsertEmailAttachment(unitOfWorkContext, @emailAttachment); } else { this.OnPostUpdateEmailAttachment(unitOfWorkContext, @emailAttachment); } return true; } }
protected abstract IEnumerable<IDataParameter> CoreGetColumnParameters(IUnitOfWorkContext unitOfWorkContext, string dataSourceTag, Database database, Schema schema, Table table);
partial void OnSelectEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
partial void OnPreInsertEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment);
partial void OnPostDeleteEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
partial void OnPostDeleteEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
partial void OnPostDeleteEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment);
partial void OnDiscardConflictEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
partial void OnDiscardConflictEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
partial void OnSelectEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment);
partial void OnPreInsertEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
partial void OnSelectEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
partial void OnPreUpdateEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment);
protected abstract IEnumerable<IDataParameter> CoreGetProcedureParameters(IUnitOfWorkContext unitOfWorkContext, string dataSourceTag, Database database, Schema schema);
partial void OnPreUpdateEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
protected abstract IEnumerable<IDataParameter> CoreGetDatabaseParameters(IUnitOfWorkContext unitOfWorkContext, string dataSourceTag);
partial void OnPreUpdateEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
public GenericRepository(IUnitOfWorkContext unitOfWorkContext) { this._context = unitOfWorkContext.GetUnitOfWorkContext() as DbContext; this._table = _context.Set <T>(); }
partial void OnSaveConflictEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment);
partial void OnPreInsertEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
public bool SaveEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage) { TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EmailMessage query; bool wasNew; if ((object)unitOfWorkContext == null) throw new ArgumentNullException("unitOfWorkContext"); if ((object)@emailMessage == null) throw new ArgumentNullException("emailMessage"); using (ContextWrapper<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext> ctx = unitOfWorkContext.GetContext<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext>()) { wasNew = @emailMessage.IsNew; if (wasNew) { this.OnPreInsertEmailMessage(unitOfWorkContext, @emailMessage); query = new TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EmailMessage(); ctx.Context.EmailMessages.InsertOnSubmit(query); } else { this.OnPreUpdateEmailMessage(unitOfWorkContext, @emailMessage); query = ctx.Context.EmailMessages.SingleOrDefault(lo => lo.@EmailMessageId == @emailMessage.@EmailMessageId); if((object)query == null) throw new InvalidOperationException("TODO (enhancement): add meaningful message"); } // map caller POCO changes to L2S object query.@EmailMessageId = @emailMessage.@EmailMessageId; query.@From = @emailMessage.@From; query.@Sender = @emailMessage.@Sender; query.@ReplyTo = @emailMessage.@ReplyTo; query.@To = @emailMessage.@To; query.@Cc = @emailMessage.@Cc; query.@Bcc = @emailMessage.@Bcc; query.@Subject = @emailMessage.@Subject; query.@IsBodyHtml = @emailMessage.@IsBodyHtml; query.@Body = @emailMessage.@Body; query.@Processed = @emailMessage.@Processed; query.@CreationTimestamp = @emailMessage.@CreationTimestamp; query.@ModificationTimestamp = @emailMessage.@ModificationTimestamp; query.@LogicalDelete = @emailMessage.@LogicalDelete; try { ctx.Context.SubmitChanges(ConflictMode.FailOnFirstConflict); } catch (ChangeConflictException ccex) { this.OnSaveConflictEmailMessage(unitOfWorkContext, @emailMessage); return false; } // map server changes back to POCO from L2S object @emailMessage.@EmailMessageId = query.@EmailMessageId; @emailMessage.@From = query.@From; @emailMessage.@Sender = query.@Sender; @emailMessage.@ReplyTo = query.@ReplyTo; @emailMessage.@To = query.@To; @emailMessage.@Cc = query.@Cc; @emailMessage.@Bcc = query.@Bcc; @emailMessage.@Subject = query.@Subject; @emailMessage.@IsBodyHtml = query.@IsBodyHtml; @emailMessage.@Body = query.@Body; @emailMessage.@Processed = query.@Processed; @emailMessage.@CreationTimestamp = query.@CreationTimestamp; @emailMessage.@ModificationTimestamp = query.@ModificationTimestamp; @emailMessage.@LogicalDelete = query.@LogicalDelete; if (wasNew) { this.OnPostInsertEmailMessage(unitOfWorkContext, @emailMessage); } else { this.OnPostUpdateEmailMessage(unitOfWorkContext, @emailMessage); } return true; } }