private async Task TraceAccountEvent( AccountEntity account, string eventName, DeviceInfo device = null, string message = null, CancellationToken token = default(CancellationToken)) { var clientIp = HttpContext.GetClientIpAddress(); var accountEventEntity = new AccountEventEntity { Id = Guid.NewGuid().ToString(), EventName = eventName, ClientIp = clientIp, LoginArea = string.Empty, UserAgent = string.Empty, // todo: Migrate to asp.net core Request.Headers.UserAgent.ToString(), Message = message }; if (account != null) { accountEventEntity.AccountName = account.AccountName; accountEventEntity.AccountId = account.Id; } if (device != null) { accountEventEntity.DeviceId = device.Id; } await this.eventTrace.TraceEvent(accountEventEntity, token); }
private AccountEventEntity GenerateTestRecord(int index) { var entity = new AccountEventEntity() { Id = DateTime.UtcNow.ToString("MMddyyyyHHmmss") + "-" + index.ToString(), AccountId = "testaccount", AccountName = "testaccountname", ClientIp = "127.0.0.1", DeviceId = "device-" + index.ToString(), EventName = "test event", Message = "test message", CreatedTime = DateTime.UtcNow, LoginArea = "ShangHai", UpdatedTime = DateTime.UtcNow, UserAgent = "user agent" }; return(entity); }
public async Task <IActionResult> Post([FromRoute] int accountId, [FromBody] AccountEventModel p_AccountEventModel) { string error; if (!p_AccountEventModel.IsValidModel(out error)) { return(BadRequest(error)); } AccountEventEntity accountEvent = new AccountEventEntity(p_AccountEventModel, accountId); List <AccountEventEntity> accountEventEntities = m_AccountEventRepository.FindAllByAccount(accountId); double totalValue = (accountEventEntities.FindAll((a) => a.Type == eEventType.Credit).Sum((b) => b.Value) - accountEventEntities.FindAll((a) => a.Type == eEventType.Debt).Sum((b) => b.Value)); if (p_AccountEventModel.Type == eEventType.Debt && p_AccountEventModel.Value > totalValue) { return(BadRequest("Valor informado para débito é maior que o saldo")); } else if (p_AccountEventModel.Type == eEventType.Debt) { totalValue = totalValue - p_AccountEventModel.Value; } else if (p_AccountEventModel.Type == eEventType.Credit) { totalValue = totalValue + p_AccountEventModel.Value; } if (m_AccountEventRepository.Insert(accountEvent)) { return(Ok(new AccountEventResponsePostModel( ) { Type = accountEvent.Type, Value = accountEvent.Value, TotalValue = totalValue })); } else { return(BadRequest("Falha ao inserir movimentação da conta")); } }