public async Task <dynamic> Execute(AddNewRecurrentExpenseMessage message) { var newRecurrentExpense = new RecurrentExpense(message.UserId, message.Name, message.Category, message.Date, new TransactionValue(message.Value), message.Until, message.Frequency); await this._dataAccess.AddNewRecurrentExpense(newRecurrentExpense); return(newRecurrentExpense); }
public async Task AddNewRecurrentExpense(RecurrentExpense recurrentExpense) { var command = "begin transaction; insert into FinancialControl.RecurrentExpenses values(@id, @until, @frequency);"; recurrentExpense.Expenses.ToList() .ForEach(e => command += $"insert into FinancialControl.Expenses values('{e.Id}', '{e.UserId}', '{e.Name}', '{e.Date}', {(int)e.Category}, {e.Value.Value}, @id);"); command += "commit;"; await this._dbConnection.ExecuteAsync(command, new { id = recurrentExpense.Id, until = recurrentExpense.Recurrency.Until, frequency = recurrentExpense.Recurrency.Frequency.Value }); }