public ConstructionSiteDocumentResponse Create(ConstructionSiteDocumentViewModel constructionSiteDocument) { ConstructionSiteDocumentResponse response = new ConstructionSiteDocumentResponse(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; try { insertCommand = AddCreateParameters(insertCommand, constructionSiteDocument); 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 ConstructionSiteDocumentResponse DeleteAll() //{ // ConstructionSiteDocumentResponse response = new ConstructionSiteDocumentResponse(); // try // { // using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) // { // db.Open(); // db.EnableExtensions(true); // SqliteCommand insertCommand = new SqliteCommand(); // insertCommand.Connection = db; // //Use parameterized query to prevent SQL injection attacks // insertCommand.CommandText = "DELETE FROM ConstructionSiteDocuments"; // try // { // insertCommand.ExecuteReader(); // } // catch (SqliteException error) // { // response.Success = false; // response.Message = error.Message; // MainWindow.ErrorMessage = error.Message; // return response; // } // db.Close(); // } // } // catch (SqliteException error) // { // response.Success = false; // response.Message = error.Message; // return response; // } // response.Success = true; // return response; //} public ConstructionSiteDocumentResponse SetStatusDeleted(Guid identifier) { ConstructionSiteDocumentResponse response = new ConstructionSiteDocumentResponse(); 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 = "UPDATE ConstructionSiteDocuments SET ItemStatus = @ItemStatus WHERE Identifier = @Identifier"; insertCommand.Parameters.AddWithValue("@ItemStatus", ItemStatus.Deleted); insertCommand.Parameters.AddWithValue("@Identifier", identifier); try { insertCommand.ExecuteReader(); } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; return(response); } db.Close(); response.Success = true; return(response); } }
public ConstructionSiteDocumentResponse GetConstructionSiteDocument(Guid identifier) { ConstructionSiteDocumentResponse response = new ConstructionSiteDocumentResponse(); ConstructionSiteDocumentViewModel ConstructionSiteDocument = new ConstructionSiteDocumentViewModel(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM ConstructionSiteDocuments " + "WHERE Identifier = @Identifier;", db); selectCommand.Parameters.AddWithValue("@Identifier", identifier); SqliteDataReader query = selectCommand.ExecuteReader(); if (query.Read()) { ConstructionSiteDocumentViewModel dbEntry = Read(query); ConstructionSiteDocument = dbEntry; } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.ConstructionSiteDocument = new ConstructionSiteDocumentViewModel(); return(response); } db.Close(); } response.Success = true; response.ConstructionSiteDocument = ConstructionSiteDocument; return(response); }