private void SaveDoc() { if (SelectedOtherDoc == null || SelectedOtherDoc.id == 0) // Create // Fill { OtherDocsEF otherDoc = new OtherDocsEF() { companyid = DataBaseClient.ReadCompanies().FirstOrDefault(c => c.name == DocCompanyName).id, brokerid = SelectedBroker.id, createdate = DocCreateDate, documenttypeid = SelectedDocType.id, number = DocNumber, inpost = false, quantity = DocQuantity }; // Save int otherDocId = 0; try { otherDocId = DataBaseClient.CreateOtherDoc(otherDoc); IncludeVis = Visibility.Visible; // Auto creation CertificateOfComplition when add InvoiceFacture if (SelectedDocType.id == 31) { OtherDocsEF cCDoc = new OtherDocsEF() { companyid = otherDoc.companyid, brokerid = SelectedBroker.id, createdate = DocCreateDate, documenttypeid = 32, number = DocNumber, inpost = false, quantity = 2 }; DataBaseClient.CreateOtherDoc(cCDoc); } } catch { MessagesService.Show("Оповещение", "Произошла ошибка во время сохранения в базу данных"); } // Update view UpdateOtherDocsList(otherDoc.companyid); SelectedOtherDoc = DataBaseClient.ReadOtherDoc(otherDocId); } else // Update // Fill fields { SelectedOtherDoc.brokerid = SelectedBroker.id; SelectedOtherDoc.createdate = DocCreateDate; SelectedOtherDoc.documenttypeid = SelectedDocType.id; SelectedOtherDoc.number = DocNumber; SelectedOtherDoc.quantity = DocQuantity; // Save changes try { DataBaseClient.UpdateOtherDoc(SelectedOtherDoc); } catch { MessagesService.Show("Оповещение", "Произошла ошибка во время сохранения в базу данных"); } // Update view UpdateOtherDocsList(SelectedOtherDoc.companyid); } DocDetailsVis = Visibility.Collapsed; }