private void AuditAnyRequiredChanges(ICommandRepository repository, IEnumerable<DbEntityEntry> modifiedItems, DbContext dbContext) { var manager = ((IObjectContextAdapter)dbContext).ObjectContext.ObjectStateManager; var relations = manager.GetObjectStateEntries(EntityState.Deleted).Where(p => p.IsRelationship); // The entityType could be either a normal type of proxy wrapper therefore we need to use GetObjectType. var auditableEntities = modifiedItems.Where(p => auditItems.Select(p1 => p1.ClassType).Contains(ObjectContext.GetObjectType(p.Entity.GetType()))); foreach (var context in auditableEntities) { // Check each property for changes var BluePearEntityType = ObjectContext.GetObjectType(context.Entity.GetType()); var auditItem = auditItems.Single(p => p.ClassType == BluePearEntityType); auditItem.AuditPropertyItems.ToList().ForEach(auditPropertyItem => { var oldValue = default(object); var currentValue = default(object); if (!auditPropertyItem.IsRelationship) { var olddbValue = context.OriginalValues.GetValue<object>(auditPropertyItem.PropertyName); var newDbValue = auditPropertyItem.PropertyInfo.GetValue(context.Entity); // Transform them if required oldValue = auditPropertyItem.GetValue(olddbValue); currentValue = auditPropertyItem.GetValue(newDbValue); } else { foreach (var deletedEntity in relations.Where(p => p.EntitySet.Name == BluePearEntityType.Name + "_" + auditPropertyItem.PropertyName)) { var entityId = ((EntityKey)deletedEntity.OriginalValues[0]).EntityKeyValues[0].Value; if ((int)entityId == ((IEntity)context.Entity).ID) { oldValue = ((EntityKey)deletedEntity.OriginalValues[1]).EntityKeyValues[0].Value; break; } } // if its null it hasn't changed if (oldValue == null) return; currentValue = ((IEntity)context.Member(auditPropertyItem.PropertyName).CurrentValue).ID; } if (!currentValue.Equals(oldValue)) { // Add the audit! var item = new AuditPropertyTrail(); item.EntityType = BluePearEntityType.Name; item.EntityId = ((IEntity)context.Entity).ID; item.PropertyName = auditPropertyItem.PropertyName; item.NewValue = currentValue.ToString(); item.OldValue = oldValue.ToString(); repository.Add(item); } }); } }
public JobStatus Command(Command command) { // validate command if (string.IsNullOrEmpty(command.Urn) || !command.Urn.ValidateUrn("job:")) { throw new ArgumentException("invalid urn", nameof(command)); } var job = _jobRepository.Get(command.Urn); if (job == null) { throw new ArgumentException("Job not found", nameof(command)); } // ReSharper disable once SwitchStatementMissingSomeCases switch (job.Plan?.GetState()) { case ExecutionState.Done: case ExecutionState.Failed: case ExecutionState.Canceled: throw new Exception($"Can't issue command job already {job.Plan.GetState()}"); } _commandRepository.Add(command); _logging.LogInfo("Received cancel event.", command); return(Mapper.Map <JobStatus>(job)); }
public Task <Command> Create(Guid actuatorId, CommandValue commandValue) { commandValue.IssueDate = DateTime.Now; // Add to database var result = _repo.Add(actuatorId, commandValue); // Start task to serial write to arduino StartWriteTask(actuatorId, result); return(result); }
public WriteConcernResult UpsertWithConcern <TEntity>(ICommandRepository repository, TEntity entity, WriteConcern writeConcern = null) where TEntity : class { if (repository == null) { throw new ArgumentNullException("repository", "repository is null."); } var interceptor = new WriteConcernAddCommandInterceptor(writeConcern ?? new WriteConcern()); repository.Add(entity, interceptor); return(interceptor.WriteConcernResult); }
public void SimpleTest() { var cmd = new Command { Type = CommandType.Cancel, Urn = "Foo", Username = "******" }; CommandRepository.Add(cmd); var dbcmds = CommandRepository.GetAll().ToList(); Assert.That(dbcmds.Count, Is.EqualTo(1)); var dbcmd = dbcmds.First(); Assert.That(dbcmd.Type, Is.EqualTo(cmd.Type)); Assert.That(dbcmd.Urn, Is.EqualTo(cmd.Urn)); Assert.That(dbcmd.Username, Is.EqualTo(cmd.Username)); CommandRepository.Remove(cmd); Assert.That(CommandRepository.GetAll(), Is.Empty); }
/// <summary> /// Processes a payment request /// </summary> /// <param name="paymentModel"></param> /// <returns></returns> public async Task <IExecutionResponse <PaymentResult> > ProcessPaymentAsync(PaymentModel paymentModel) { _logger.LogInformation($"Processing payment..."); PaymentResult paymentResult; string userName = GetLoggedInUser(); if (paymentModel.Amount < 0) { _logger.LogInformation("Cannot process payment for amounts less than 0"); paymentResult = PaymentResultMapping.CreateEntity(400, "An error occured"); return(_responseFactory.ExecutionResponse <PaymentResult>("Cannot process payment for amounts less than 0", paymentResult, statusCode: 400)); } // Default result PaymentResult thirdPartyResponse = new PaymentResult { Message = "An error occurred", StatusCode = 500 }; if (paymentModel.Amount < 20) { // Use ICheapPaymentGateway. No retry thirdPartyResponse = _cheapPaymentGateway.BankTransfer(paymentModel); } else if (paymentModel.Amount >= 21 && paymentModel.Amount <= 500) { // Use IExpensivePaymentGateway and retry once with ICheapPaymentGateway thirdPartyResponse = RetryWithCheapPaymentGateway(paymentModel); } else if (paymentModel.Amount > 500) { // Use PremiumPaymentService and retry 3 times thirdPartyResponse = RetryThriceWithPremiumGateway(paymentModel); } var payment = PaymentMapping.CreateEntity(paymentModel, userName, userName); // Map response from third party var paymentState = UpdatePaymentStateFromThirdParty(payment, thirdPartyResponse.StatusCode); // Save to DB _commandRepostory.Add(payment); _paymentStateCommandRepostory.Add(paymentState); await _commandRepostory.SaveAsync(); // Send thirdPartyResponse as the response data, in case an integrator wants to change transaction status based on status code _logger.LogInformation("Payment processed successfully."); return(_responseFactory.ExecutionResponse <PaymentResult>(thirdPartyResponse.Message, statusCode: thirdPartyResponse.StatusCode, data: thirdPartyResponse, status: true)); }
public void Handle(Command command) { _commandRepository.Add(command); _commandRepository.Commit(); _validator.Validate(command); command.Execute(); if (!_validator.HasValidations()) { _eventBus.Dispatch(); _uoW.Commit(); } }
public void Execute(CreateProductCommand command) { if (command == null) { throw new ArgumentNullException("command"); } var product = new Product { //Id = command.Id,//pk identity(1,1) Name = command.Name, Description = command.Description, Stock = command.Stock, Price = command.Price }; _commandProductRepository.Add(product); _commandProductRepository.Save(); }
public Result <int> Save(PostingItem entity) { switch (entity.EntityState) { case ItemState.Added: return(_commandRepository.Add(entity.MapTo <Postings>()).MapResultTo <int, object>()); case ItemState.Modified: return(_commandRepository.InlineUpdate(entity, entity.Id)); case ItemState.Delete: return(_commandRepository.Delete(entity.Id)); case ItemState.Unchanged: return(Result <int> .Fail <int>("Unchanged Object. Nothing to save")); default: return(Result <int> .Fail <int>("Entity state unknown")); } }
public Result <int> Save(CodeMapperItem entity) { switch (entity.EntityState) { case ItemState.Added: return(_commandRepository.Add(entity.MapTo <CodeMappers>()).MapResultTo <int, object>()); case ItemState.Modified: if (!entity.IsDefault) { return(_commandRepository.InlineUpdate(entity, entity.Id)); } return(ResetDefault().Bind <int>(x => _commandRepository.InlineUpdate(entity, entity.Id))); case ItemState.Delete: return(_commandRepository.Delete(entity.Id)); case ItemState.Unchanged: return(Result <int> .Fail <int>("Unchanged Object. Nothing to save")); default: return(Result <int> .Fail <int>("Entity state unknown")); } }
public Guid CreateTopic(Topic topic) { _commandRepository.Add(topic); return(topic.SysId); }
private void AuditAnyRequiredChanges(ICommandRepository repository, IEnumerable <DbEntityEntry> modifiedItems, DbContext dbContext) { var manager = ((IObjectContextAdapter)dbContext).ObjectContext.ObjectStateManager; var relations = manager.GetObjectStateEntries(EntityState.Deleted).Where(p => p.IsRelationship); // The entityType could be either a normal type of proxy wrapper therefore we need to use GetObjectType. var auditableEntities = modifiedItems.Where(p => auditItems.Select(p1 => p1.ClassType).Contains(ObjectContext.GetObjectType(p.Entity.GetType()))); foreach (var context in auditableEntities) { // Check each property for changes var BluePearEntityType = ObjectContext.GetObjectType(context.Entity.GetType()); var auditItem = auditItems.Single(p => p.ClassType == BluePearEntityType); auditItem.AuditPropertyItems.ToList().ForEach(auditPropertyItem => { var oldValue = default(object); var currentValue = default(object); if (!auditPropertyItem.IsRelationship) { var olddbValue = context.OriginalValues.GetValue <object>(auditPropertyItem.PropertyName); var newDbValue = auditPropertyItem.PropertyInfo.GetValue(context.Entity); // Transform them if required oldValue = auditPropertyItem.GetValue(olddbValue); currentValue = auditPropertyItem.GetValue(newDbValue); } else { foreach (var deletedEntity in relations.Where(p => p.EntitySet.Name == BluePearEntityType.Name + "_" + auditPropertyItem.PropertyName)) { var entityId = ((EntityKey)deletedEntity.OriginalValues[0]).EntityKeyValues[0].Value; if ((int)entityId == ((IEntity)context.Entity).ID) { oldValue = ((EntityKey)deletedEntity.OriginalValues[1]).EntityKeyValues[0].Value; break; } } // if its null it hasn't changed if (oldValue == null) { return; } currentValue = ((IEntity)context.Member(auditPropertyItem.PropertyName).CurrentValue).ID; } if (!currentValue.Equals(oldValue)) { // Add the audit! var item = new AuditPropertyTrail(); item.EntityType = BluePearEntityType.Name; item.EntityId = ((IEntity)context.Entity).ID; item.PropertyName = auditPropertyItem.PropertyName; item.NewValue = currentValue.ToString(); item.OldValue = oldValue.ToString(); repository.Add(item); } }); } }
public void Add(T item) { _commandRepository.Add(item); }
public void Create(Account account) { _commandRepository.Add(account); }
public Result <int> Add(UserItem entity) => _commandRepository.Add(entity.MapTo <Users>()).MapResultTo <int, object>();
public Guid CreateUserDevice(UserDevice userDevice) { _commandRepository.Add(userDevice); return(userDevice.SysId); }
public virtual void AddHeaders(IEnumerable <CommandHeader> command_headers) { _commandRepository.Add(command_headers); }
public Result <int> Add(JournalEntryItem entity) => _commandRepository.Add(entity.MapTo <JournalEntries>()).MapResultTo <int, object>();
public Result <int> Add(AccountItem entity) => _commandRepository.Add(entity.MapTo <Accounts>()).MapResultTo <int, object>();
public Guid CreateUser(SysUser user) { _commandRepository.Add(user); return(user.SysId); }