public InputInvoiceResponse Delete(Guid identifier) { InputInvoiceResponse response = new InputInvoiceResponse(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); SqliteCommand insertCommand = new SqliteCommand(); insertCommand.Connection = db; //Use parameterized query to prevent SQL injection attacks insertCommand.CommandText = "DELETE FROM InputInvoices WHERE Identifier = @Identifier"; insertCommand.Parameters.AddWithValue("@Identifier", identifier); try { insertCommand.ExecuteNonQuery(); } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; return(response); } db.Close(); response.Success = true; return(response); } }
public InputInvoiceResponse Create(InputInvoiceViewModel InputInvoice) { InputInvoiceResponse response = new InputInvoiceResponse(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; try { insertCommand = AddCreateParameters(insertCommand, InputInvoice); insertCommand.ExecuteNonQuery(); } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; return(response); } db.Close(); response.Success = true; return(response); } }
public InputInvoiceResponse Create(InputInvoiceViewModel re) { InputInvoiceResponse response = new InputInvoiceResponse(); try { response = WpfApiHandler.SendToApi <InputInvoiceViewModel, InputInvoiceResponse>(re, "Create"); } catch (Exception ex) { response.InputInvoice = new InputInvoiceViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
private void BtnSubmit_Click(object sender, RoutedEventArgs e) { #region Validation if (InputInvoiceDocumentsFromDB == null || InputInvoiceDocumentsFromDB.Count == 0) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Morate_uneti_osnovne_podatkeUzvičnik")); return; } #endregion Thread td = new Thread(() => { SubmitButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke")); SubmitButtonEnabled = false; CurrentInputInvoice.InputInvoiceDocuments = InputInvoiceDocumentsFromDB; InputInvoiceResponse response = inputInvoiceService.Create(CurrentInputInvoice); if (!response.Success) { MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_čuvanja_na_serveruUzvičnik")); SubmitButtonContent = ((string)Application.Current.FindResource("Proknjiži")); SubmitButtonEnabled = true; } if (response.Success) { MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik")); SubmitButtonContent = ((string)Application.Current.FindResource("Proknjiži")); SubmitButtonEnabled = true; InputInvoiceCreatedUpdated(); Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { FlyoutHelper.CloseFlyout(this); }) ); } }); td.IsBackground = true; td.Start(); }
public InputInvoiceResponse Delete(Guid identifier) { InputInvoiceResponse response = new InputInvoiceResponse(); try { InputInvoiceViewModel re = new InputInvoiceViewModel(); re.Identifier = identifier; response = WpfApiHandler.SendToApi <InputInvoiceViewModel, InputInvoiceResponse>(re, "Delete"); } catch (Exception ex) { response.InputInvoice = new InputInvoiceViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Delete([FromBody] InputInvoiceViewModel inputInvoice) { InputInvoiceResponse response = new InputInvoiceResponse(); try { response = this.inputInvoiceService.Delete(inputInvoice.Identifier); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; Console.WriteLine(ex.Message); } return(Json(response, new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.Indented })); }
public InputInvoiceResponse Delete(Guid identifier) { InputInvoiceResponse response = new InputInvoiceResponse(); try { DomainCore.Common.InputInvoices.InputInvoice deletedInputInvoice = unitOfWork.GetInputInvoiceRepository().Delete(identifier); unitOfWork.Save(); response.InputInvoice = deletedInputInvoice.ConvertToInputInvoiceViewModel(); response.Success = true; } catch (Exception ex) { response.InputInvoice = new InputInvoiceViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public InputInvoiceResponse GetInputInvoice(Guid identifier) { InputInvoiceResponse response = new InputInvoiceResponse(); InputInvoiceViewModel InputInvoice = new InputInvoiceViewModel(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM InputInvoices " + "WHERE Identifier = @Identifier;", db); selectCommand.Parameters.AddWithValue("@Identifier", identifier); SqliteDataReader query = selectCommand.ExecuteReader(); if (query.Read()) { InputInvoiceViewModel dbEntry = Read(query); InputInvoice = dbEntry; } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.InputInvoice = new InputInvoiceViewModel(); return(response); } db.Close(); } response.Success = true; response.InputInvoice = InputInvoice; return(response); }
public InputInvoiceResponse Create(InputInvoiceViewModel re) { InputInvoiceResponse response = new InputInvoiceResponse(); try { // Backup notes List <InputInvoiceNoteViewModel> inputInvoiceNotes = re.InputInvoiceNotes?.ToList(); re.InputInvoiceNotes = null; // Backup documents List <InputInvoiceDocumentViewModel> inputInvoiceDocuments = re.InputInvoiceDocuments?.ToList(); re.InputInvoiceDocuments = null; InputInvoice createdInputInvoice = unitOfWork.GetInputInvoiceRepository().Create(re.ConvertToInputInvoice()); // Update notes if (inputInvoiceNotes != null && inputInvoiceNotes.Count > 0) { // Items for create or update foreach (var inputInvoiceNote in inputInvoiceNotes .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <InputInvoiceNoteViewModel>()) { inputInvoiceNote.InputInvoice = new InputInvoiceViewModel() { Id = createdInputInvoice.Id }; inputInvoiceNote.ItemStatus = ItemStatus.Submited; InputInvoiceNote createdInputInvoiceNote = unitOfWork.GetInputInvoiceNoteRepository() .Create(inputInvoiceNote.ConvertToInputInvoiceNote()); } foreach (var item in inputInvoiceNotes .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <InputInvoiceNoteViewModel>()) { item.InputInvoice = new InputInvoiceViewModel() { Id = createdInputInvoice.Id }; unitOfWork.GetInputInvoiceNoteRepository().Create(item.ConvertToInputInvoiceNote()); unitOfWork.GetInputInvoiceNoteRepository().Delete(item.Identifier); } } // Update documents if (inputInvoiceDocuments != null && inputInvoiceDocuments.Count > 0) { // Items for create or update foreach (var inputInvoiceDocument in inputInvoiceDocuments .Where(x => x.ItemStatus == ItemStatus.Added || x.ItemStatus == ItemStatus.Edited)?.ToList() ?? new List <InputInvoiceDocumentViewModel>()) { inputInvoiceDocument.InputInvoice = new InputInvoiceViewModel() { Id = createdInputInvoice.Id }; inputInvoiceDocument.ItemStatus = ItemStatus.Submited; InputInvoiceDocument createdInputInvoiceDocument = unitOfWork.GetInputInvoiceDocumentRepository() .Create(inputInvoiceDocument.ConvertToInputInvoiceDocument()); } foreach (var item in inputInvoiceDocuments .Where(x => x.ItemStatus == ItemStatus.Deleted)?.ToList() ?? new List <InputInvoiceDocumentViewModel>()) { item.InputInvoice = new InputInvoiceViewModel() { Id = createdInputInvoice.Id }; unitOfWork.GetInputInvoiceDocumentRepository().Create(item.ConvertToInputInvoiceDocument()); unitOfWork.GetInputInvoiceDocumentRepository().Delete(item.Identifier); } } unitOfWork.Save(); response.InputInvoice = createdInputInvoice.ConvertToInputInvoiceViewModel(); response.Success = true; } catch (Exception ex) { response.InputInvoice = new InputInvoiceViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }