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); }
private void PopulateItems() { for (int i = 0; i < NUM_ITEMS; ++i) { var commerce = new Bogus.DataSets.Commerce(); var hacker = new Bogus.DataSets.Hacker(); var invoice = GetRandomElement(InvoiceService.AllItems); InvoiceItem item = new InvoiceItem(-1, DateTime.Now, string.Empty, commerce.ProductName(), Convert.ToDecimal(commerce.Price(15, 500)), Math.Round((decimal)(random.NextDouble() / 5d), 2), invoice.Id); ItemsService.CreateEntry(item); invoice.Items.Add(item); } }
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); }