public void CompleteSaving(ISaving saving) { var reservations = GetReservations(saving.SavingId).ToList(); var i = 0; using (var connection = _connection.SqlConnection) { var commands = reservations.Select(reservation => new SqlCommand("INSERT INTO dbo.[Transaction] ([Name],Amount,TimeOfTransaction,AccountId,Category,IconId) VALUES('Saving Reservation',@Amount,@Time,@AccountId,'SavingPlan',@IconId)", connection)).ToList(); foreach (var command in commands) { command.Parameters.AddWithValue("@Amount", -reservations[i].Amount); command.Parameters.AddWithValue("@Time", DateTime.Now); command.Parameters.AddWithValue("@AccountId", reservations[i].AccountId); command.Parameters.AddWithValue("IconId", 0); i++; } connection.Open(); foreach (var command in commands) { command.ExecuteNonQuery(); } connection.Close(); } RemoveReservations(saving.SavingId); }
public void UpdateSaving(ISaving saving) { using (var connection = _connection.SqlConnection) { var command = new SqlCommand("UPDATE dbo.Savings set SavingsName=@Name,CurrentAmount=@Current,GoalAmount=@Goal,IconId=@IconId,[State]=@State,GoalDate=@GoalDate WHERE SavingsId=@Id", connection); command.Parameters.AddWithValue("@Id", saving.SavingId); command.Parameters.AddWithValue("@Name", saving.SavingName); command.Parameters.AddWithValue("@Current", saving.SavingCurrentAmount); command.Parameters.AddWithValue("@Goal", saving.SavingsGoalAmount); command.Parameters.AddWithValue("@IconId", saving.IconId); command.Parameters.AddWithValue("@State", (int)saving.State); command.Parameters.AddWithValue("@GoalDate", saving.GoalDate); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } }
public void CreateSaving(ISaving saving) { using (var connection = _connection.SqlConnection) { var command = new SqlCommand("INSERT INTO dbo.Savings (UserId,SavingsName,CurrentAmount,IconId,GoalAmount,[State],DateOfCreation,GoalDate) VALUES(@UserId,@Name,@Current,@IconId,@Goal,@State,@DateOfC, @GoalDate)", connection); command.Parameters.AddWithValue("@Name", saving.SavingName); command.Parameters.AddWithValue("@Current", saving.SavingCurrentAmount); command.Parameters.AddWithValue("@Goal", saving.SavingsGoalAmount); command.Parameters.AddWithValue("@IconId", saving.IconId); command.Parameters.AddWithValue("@State", (int)saving.State); command.Parameters.AddWithValue("@GoalDate", saving.GoalDate); command.Parameters.AddWithValue("@UserId", saving.UserId); command.Parameters.AddWithValue("@DateOfC", DateTime.Now); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } }
public static void AddSaving(ISaving saving) { _savers.Add(saving); }
public static void RemoveSaving(ISaving saving) { _savers.Remove(saving); }
public Logic(ISaving saving, ILogger <Logic> logger) { _saving = saving; _logger = logger; }
public void CompleteSaving(ISaving saving) { _context.CompleteSaving(saving); }
public void UpdateSaving(ISaving saving) { _context.UpdateSaving(saving); }
public void CreateSaving(ISaving saving) { _context.CreateSaving(saving); }