private void ValidateAccuracy(CashOperationsFee cashOperationsFee, AssetModel asset) { var cashInStr = cashOperationsFee.CashInValue.ToString(CultureInfo.InvariantCulture); var cashInFractionLength = cashInStr.Substring(cashInStr.IndexOf(".") + 1).Length; if (cashInFractionLength > asset.Accuracy) { throw new IncorrectAccuracyException(ErrorCode.IncorrectAccuracy, "CashIn accuracy is bigger then asset accuracy."); } var cashOutStr = cashOperationsFee.CashOutValue.ToString(CultureInfo.InvariantCulture); var cashOutFractionLength = cashOutStr.Substring(cashOutStr.IndexOf(".") + 1).Length; if (cashOutFractionLength > asset.Accuracy) { throw new IncorrectAccuracyException(ErrorCode.IncorrectAccuracy, "CashOut accuracy is bigger then asset accuracy."); } var cashTransferStr = cashOperationsFee.CashTransferValue.ToString(CultureInfo.InvariantCulture); var cashTransferFractionLength = cashTransferStr.Substring(cashTransferStr.IndexOf(".") + 1).Length; if (cashTransferFractionLength > asset.Accuracy) { throw new IncorrectAccuracyException(ErrorCode.IncorrectAccuracy, "CashTransfer accuracy is bigger then asset accuracy."); } }
public async Task <CashOperationsFee> UpdateAsync(CashOperationsFee cashOperationsFee) { using (var context = _connectionFactory.CreateDataContext()) { var data = await GetAsync(cashOperationsFee.Id, cashOperationsFee.BrokerId, context); if (data == null) { throw new EntityNotFoundException(ErrorCode.ItemNotFound, $"{typeof(CashOperationsFee)} with id '{cashOperationsFee.Id}' does not exist."); } // save fields that has not be updated var asset = data.Asset; var created = data.Created; _mapper.Map(cashOperationsFee, data); // restore fields that has not be updated data.Asset = asset; data.Created = created; data.Modified = DateTime.UtcNow; await context.SaveChangesAsync(); return(_mapper.Map <CashOperationsFee>(data)); } }
public CashOperationsFeeModel(CashOperationsFee cashOperationsFee) { Id = cashOperationsFee.Id; BrokerId = cashOperationsFee.BrokerId; Asset = cashOperationsFee.Asset; CashInValue = decimal.Parse(cashOperationsFee.CashInValue); CashInFeeType = (CashOperationsFeeTypeModel)cashOperationsFee.CashInFeeType; CashOutValue = decimal.Parse(cashOperationsFee.CashOutValue); CashOutFeeType = (CashOperationsFeeTypeModel)cashOperationsFee.CashOutFeeType; CashTransferValue = decimal.Parse(cashOperationsFee.CashTransferValue); CashTransferFeeType = (CashOperationsFeeTypeModel)cashOperationsFee.CashTransferFeeType; Created = cashOperationsFee.Created.ToDateTime(); Modified = cashOperationsFee.Modified.ToDateTime(); }
public async Task <CashOperationsFee> UpdateAsync(string userId, CashOperationsFee cashOperationsFee) { //var asset = await GetAsset(cashOperationsFee.BrokerId, cashOperationsFee.Asset); //ValidateAccuracy(cashOperationsFee, asset); var result = await _cashOperationsFeeRepository.UpdateAsync(cashOperationsFee); var history = _mapper.Map <CashOperationsFeeHistory>(result); history.UserId = userId; history.OperationType = HistoryOperationType.Modified; await _cashOperationsFeeHistoryRepository.InsertAsync(history); _logger.LogInformation("CashOperationsFee has been updated. {@CashOperationsFee}", result); return(result); }
private CashOperationsFee Map(Domain.Entities.CashOperationsFee domain) { if (domain == null) { return(null); } var model = new CashOperationsFee(); model.Id = domain.Id; model.BrokerId = domain.BrokerId; model.Asset = domain.Asset; model.CashInValue = domain.CashInValue.ToString(CultureInfo.InvariantCulture); model.CashInFeeType = (CashOperationsFeeType)domain.CashInFeeType; model.CashOutValue = domain.CashOutValue.ToString(CultureInfo.InvariantCulture); model.CashOutFeeType = (CashOperationsFeeType)domain.CashOutFeeType; model.CashTransferValue = domain.CashTransferValue.ToString(CultureInfo.InvariantCulture); model.CashTransferFeeType = (CashOperationsFeeType)domain.CashTransferFeeType; model.Created = Timestamp.FromDateTime(domain.Created); model.Modified = Timestamp.FromDateTime(domain.Modified); return(model); }
public async Task <CashOperationsFee> InsertAsync(CashOperationsFee cashOperationsFee) { using (var context = _connectionFactory.CreateDataContext()) { var existedAsset = await GetAsync(cashOperationsFee.BrokerId, cashOperationsFee.Asset, context); if (existedAsset != null) { throw new DuplicatedEntityException(ErrorCode.DuplicateItem, $"CashOperationsFee with id '{cashOperationsFee.Id}' already exists."); } var data = _mapper.Map <CashOperationsFeeEntity>(cashOperationsFee); data.Created = DateTime.UtcNow; data.Modified = data.Created; context.CashOperationsFees.Add(data); await context.SaveChangesAsync(); return(_mapper.Map <CashOperationsFee>(data)); } }