public object Deposit([FromBody] DepositPayload input) { decimal newBalance = Decimal.Parse(input.deposit) + input.currentDeposit; Dictionary <string, object> fieldsToUpdate = new Dictionary <string, object>(); fieldsToUpdate.Add("balance", newBalance); fieldsToUpdate.Add("modifiedDate", DateTime.UtcNow.ToString()); try { BsonDocument result = MongoDBHelperSingleton.instance.GetRecordAndUpdate(input.accountId, fieldsToUpdate, "AccountCollection"); if (result != null) { return(new { success = true, data = new { newBalance } }); } else { return(new { success = false, message = "Unexpected error updating the record" }); } } catch (Exception e) { return(new { success = false, message = "Unexpected error updating the record", errorCode = "500" }); } }
public object Deposit([FromBody] DepositPayload input) { decimal newBalance = Decimal.Parse(input.deposit) + input.currentDeposit; Dictionary <string, object> fieldsToUpdate = new Dictionary <string, object>(); fieldsToUpdate.Add("balance", newBalance); fieldsToUpdate.Add("modifiedDate", DateTime.UtcNow.ToString()); string xcv = Guid.NewGuid().ToString(); try { using (_logger.BeginScope(new Dictionary <string, object>() { { "xcv", xcv } })) { _logger.LogInformation("Started Deposit"); } BsonDocument result = MongoDBHelperSingleton.instance.GetRecordAndUpdate(input.accountId, fieldsToUpdate, "AccountCollection"); if (result != null) { return(new { success = true, data = new { newBalance } }); } else { using (_logger.BeginScope(new Dictionary <string, object>() { { "xcv", xcv }, { "message", "Unexpected error updating the record" }, { "errorCode", "500" } })) { _logger.LogError(new Exception(), "Unexpected exception in updating the record"); } return(new { success = false, message = "Unexpected error updating the record", errorCode = "500" }); } } catch (Exception e) { using (_logger.BeginScope(new Dictionary <string, object>() { { "xcv", xcv }, { "message", e.Message }, { "errorCode", "500" } })) { _logger.LogError(e, "Unexpected exception in depositing balance"); } return(new { success = false, message = "Unexpected error updating the record", errorCode = "500" }); } }