public async Task UpdateAsync(ILoanOffer loanOffer) { var request = CreateUpdateItemRequest(loanOffer); var response = await _dynamoDbClient.UpdateItemAsync(request); if (response.HttpStatusCode != HttpStatusCode.OK) { throw new FailedToUpdateLoanOfferInDynamoDbException(response.HttpStatusCode); } }
public async Task AddAsync(ILoanOffer loanOffer) { var request = CreatePutLoanOfferRequest(loanOffer); var response = await _dynamoDbClient.PutItemAsync(request); if (response.HttpStatusCode != HttpStatusCode.OK) { throw new FailedToPutLoanOfferToDynamoDbException(response.HttpStatusCode); } }
private static UpdateItemRequest CreateUpdateItemRequest(ILoanOffer loanOffer) => new UpdateItemRequest { TableName = LoanOfferTableName, Key = GetDictionaryWithIdAttribute(loanOffer.Id), AttributeUpdates = new Dictionary <string, AttributeValueUpdate> { { RequestedLoanAmountDynamoFiledName, new AttributeValueUpdate(new AttributeValue { N = loanOffer.RequestedLoanAmount.ToString() }, AttributeAction.PUT) } } };
public async Task UpdateAsync(ILoanOffer loanOffer) { using (var db = new LoanOfferContext()) { var loan = await db.LoanOffers.FirstOrDefaultAsync(x => x.Id == loanOffer.Id.Value); if (loan == null) { return; } loan.RequestedLoanAmount = loanOffer.RequestedLoanAmount.Value; await db.SaveChangesAsync(); } }
public async Task AddAsync(ILoanOffer loanOffer) { using (var db = new LoanOfferContext()) { db.LoanOffers.Add( new LoanOfferDTO { Id = loanOffer.Id.Value, Pesel = loanOffer.PeselNumber.Value, EmailAddress = loanOffer.EmailAddress.Value, MaxLoanAmount = loanOffer.MaxLoanAmount.Value, RequestedLoanAmount = loanOffer.RequestedLoanAmount.Value } ); await db.SaveChangesAsync(); } }
private static PutItemRequest CreatePutLoanOfferRequest(ILoanOffer loanOffer) => new PutItemRequest { TableName = LoanOfferTableName, Item = new Dictionary <string, AttributeValue> { { IdDynamoFieldName, new AttributeValue { S = loanOffer.Id.ToString() } }, { PeselNumberDynamoFieldName, new AttributeValue { S = loanOffer.PeselNumber.Value } }, { EmailAddressDynamoFieldName, new AttributeValue { S = loanOffer.EmailAddress.Value } }, { MaxLoanAmountDynamoFieldName, new AttributeValue { N = loanOffer.MaxLoanAmount.ToString() } } } };