public string CreateInvoice(InvoicePostDto newInvoice) { var userSrv = new UserService(bmsData); Invoice invoice; invoice = new Invoice() { InvoiceNum = int.Parse(newInvoice.InvoiceNum), ClientId = (int)newInvoice.ClientId, SupplierId = (int)newInvoice.SupplierId, ProjectId = newInvoice.ProjectId, Date = newInvoice.Date, Town = newInvoice.Town, Text = newInvoice.Text, BankRequisits = newInvoice.BankRequisits, Price = newInvoice.Price, Vat = newInvoice.Vat, Total = newInvoice.Total }; bmsData.Invoices.Add(invoice); bmsData.SaveChanges(); return($"Invoice with number {newInvoice.InvoiceNum} from date {newInvoice.Date.ToShortDateString()} successfully created!"); }
private void HandleSaveCommand(object parameter) { var result = string.Empty; try { var newInvoice = new InvoicePostDto() { Id = this.Id, InvoiceNum = this.InvoiceNum, Town = this.InvoiceTown, Text = this.InvoiceText, BankRequisits = this.InvoiceBankRequisits, ClientId = this.SelectedClient.Id, SupplierId = this.SelectedSupplier.Id, ProjectId = this.SelectedProject.Id, Date = this.InvoiceDate, Price = this.InvoicePrice, Vat = this.InvoiceVat, Total = this.InvoiceTotal }; if (this.SelectedInvoice == null) { result = this.InvoiceService.CreateInvoice(newInvoice); MessageBox.Show(result); this.RedirectToPreviousWindow(); } else { result = this.InvoiceService.EditInvoice(newInvoice); MessageBox.Show(result); this.RedirectToPreviousWindow(); } } catch (Exception e) { result = e.Message; MessageBox.Show(result); } }
public string EditInvoice(InvoicePostDto newInvoice) { var invoiceToUpdate = bmsData.Invoices.Find(newInvoice.Id); invoiceToUpdate.InvoiceNum = int.Parse(newInvoice.InvoiceNum); invoiceToUpdate.ClientId = newInvoice.ClientId; invoiceToUpdate.SupplierId = newInvoice.SupplierId; invoiceToUpdate.ProjectId = newInvoice.ProjectId; invoiceToUpdate.Date = newInvoice.Date; invoiceToUpdate.Town = newInvoice.Town; invoiceToUpdate.Text = newInvoice.Text; invoiceToUpdate.BankRequisits = newInvoice.BankRequisits; invoiceToUpdate.Price = newInvoice.Price; invoiceToUpdate.Vat = newInvoice.Vat; invoiceToUpdate.Total = newInvoice.Total; bmsData.Invoices.Update(invoiceToUpdate); bmsData.SaveChanges(); return($"Invoice with Serial Number {newInvoice.InvoiceNum} successfully updated!"); }