public VatResponse Delete(Guid identifier) { VatResponse response = new VatResponse(); 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 Vats 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 VatResponse Create(VatViewModel vat) { VatResponse response = new VatResponse(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; try { insertCommand = AddCreateParameters(insertCommand, vat); 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 VatResponse Create(VatViewModel Vat) { VatResponse response = new VatResponse(); try { response = WpfApiHandler.SendToApi <VatViewModel, VatResponse>(Vat, "Create"); } catch (Exception ex) { response.Vat = new VatViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public VatResponse Delete(Guid identifier) { VatResponse response = new VatResponse(); try { VatViewModel Vat = new VatViewModel(); Vat.Identifier = identifier; response = WpfApiHandler.SendToApi <VatViewModel, VatResponse>(Vat, "Delete"); } catch (Exception ex) { response.Vat = new VatViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public VatResponse Delete(Guid identifier) { VatResponse response = new VatResponse(); try { Vat deletedVat = unitOfWork.GetVatRepository().Delete(identifier); unitOfWork.Save(); response.Vat = deletedVat.ConvertToVatViewModel(); response.Success = true; } catch (Exception ex) { response.Vat = new VatViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public VatResponse Create(VatViewModel re) { VatResponse response = new VatResponse(); try { Vat addedVat = unitOfWork.GetVatRepository().Create(re.ConvertToVat()); unitOfWork.Save(); response.Vat = addedVat.ConvertToVatViewModel(); response.Success = true; } catch (Exception ex) { response.Vat = new VatViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { Thread th = new Thread(() => { VatDataLoading = true; if (CurrentVat == null) { MainWindow.WarningMessage = (string)Application.Current.FindResource("Morate_izabrati_stavku"); VatDataLoading = false; return; } VatResponse response = VatService.Delete(CurrentVat.Identifier); if (!response.Success) { MainWindow.ErrorMessage = (string)Application.Current.FindResource("Greška_kod_brisanja_sa_serveraUzvičnik"); VatDataLoading = false; return; } response = new VatSQLiteRepository().Delete(CurrentVat.Identifier); if (!response.Success) { MainWindow.ErrorMessage = (string)Application.Current.FindResource("Greška_kod_lokalnog_brisanjaUzvičnik"); VatDataLoading = false; return; } MainWindow.SuccessMessage = (string)Application.Current.FindResource("Stavka_je_uspešno_obrisanaUzvičnik"); DisplayVatData(); VatDataLoading = false; }); th.IsBackground = true; th.Start(); }
public JsonResult Delete([FromBody] VatViewModel Vat) { VatResponse response = new VatResponse(); try { response = this.VatService.Delete(Vat.Identifier); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; Console.WriteLine(ex.Message); } JsonResult result = Json(response, new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.Indented, ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize }); return(result); }
public VatResponse GetVat(Guid identifier) { VatResponse response = new VatResponse(); VatViewModel vat = null; using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM Vats " + "WHERE Identifier = @Identifier;", db); selectCommand.Parameters.AddWithValue("@Identifier", identifier); SqliteDataReader query = selectCommand.ExecuteReader(); if (query.Read()) { vat = Read(query); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.Vat = new VatViewModel(); return(response); } db.Close(); } response.Success = true; response.Vat = vat; return(response); }