public override bool UpdateEntry(Invoice updatedValue) { bool invoiceUpdated, itemsUpdated = true, paymentsUpdated = true; using (var command = new SqliteCommand()) { string updateQuery = $"UPDATE {TableName} SET ClientID=@ClientID, InvoiceDate=@InvoiceDate, Type=@Type, Paid=@Paid, DueDate=@DueDate, Note=@Note" + " WHERE InvoiceID=@InvoiceID;"; command.CommandText = updateQuery; SetParameters(command, updatedValue); command.Parameters.Add(new SqliteParameter("@InvoiceID", DbType.Int32) { Value = updatedValue.Id }); invoiceUpdated = DBService.UpdateValue(command); } foreach (var item in updatedValue.Items) { itemsUpdated = itemsUpdated && (item.Id >= 0) ? ItemsService.UpdateEntry(item) : ItemsService.CreateEntry(item).Id >= 0; } foreach (var payment in updatedValue.Payments) { paymentsUpdated = paymentsUpdated && (payment.Id >= 0) ? PaymentsService.UpdateEntry(payment) : PaymentsService.CreateEntry(payment).Id >= 0; } return(invoiceUpdated && itemsUpdated && paymentsUpdated); }
public static void InstantiateServices() { SettingsService = new SettingsService(); DBService = new DBService(); PDFService = new PDFService(SettingsService); ClientService = new ClientService(DBService); ItemsService = new ItemsService(DBService); PaymentsService = new PaymentsService(DBService); InvoiceService = new InvoiceService(DBService, ClientService, ItemsService, PDFService, SettingsService, PaymentsService); ExpenseService = new ExpenseService(DBService, InvoiceService); BusinessStatsService = new BusinessStatsService(ClientService, InvoiceService, ExpenseService, PaymentsService); //DemoDataService = new DemoDataService(DBService, ClientService, ExpenseService, InvoiceService, ItemsService, PaymentsService); }
public override Invoice CreateEntry(Invoice newValue) { if (newValue.Id != -1) { throw new ArgumentException("Invalid invoice entry creation, Id is already set."); } else if (newValue.Client == null) { throw new ArgumentException("Invalid invoice entry creation, client has not been set."); } using (var command = new SqliteCommand()) { string insertQuery = $"INSERT INTO {TableName} ({string.Join(", ", Enum.GetNames(typeof(Columns)).Skip(1))})" + "VALUES (@CreationDate, @Note, @ClientID, @InvoiceDate, @Type, @Paid, @DueDate);"; command.CommandText = insertQuery; SetParameters(command, newValue); command.Parameters.Add(new SqliteParameter("@CreationDate", DbType.DateTime) { Value = newValue.CreationDate }); newValue.Id = DBService.InsertValue(command); } AllItems.Add(newValue); foreach (var item in newValue.Items) { item.InvoiceId = newValue.Id; ItemsService.CreateEntry(item); } foreach (var payment in newValue.Payments) { payment.InvoiceId = newValue.Id; PaymentsService.CreateEntry(payment); } return(newValue); }