public MunicipalityResponse Delete(Guid identifier) { MunicipalityResponse response = new MunicipalityResponse(); using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); SqliteCommand insertCommand = new SqliteCommand(); insertCommand.Connection = db; //Use parameterized query to prevent SQL injection attacks insertCommand.CommandText = "DELETE FROM Municipalities 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 MunicipalityResponse Create(MunicipalityViewModel Municipality) { MunicipalityResponse response = new MunicipalityResponse(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; try { insertCommand = AddCreateParameters(insertCommand, Municipality); 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 MunicipalityResponse Create(MunicipalityViewModel re) { MunicipalityResponse response = new MunicipalityResponse(); try { response = WpfApiHandler.SendToApi <MunicipalityViewModel, MunicipalityResponse>(re, "Create"); } catch (Exception ex) { response.Municipality = new MunicipalityViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public MunicipalityResponse Delete(Guid identifier) { MunicipalityResponse response = new MunicipalityResponse(); try { MunicipalityViewModel re = new MunicipalityViewModel(); re.Identifier = identifier; response = WpfApiHandler.SendToApi <MunicipalityViewModel, MunicipalityResponse>(re, "Delete"); } catch (Exception ex) { response.Municipality = new MunicipalityViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public MunicipalityResponse Create(MunicipalityViewModel re) { MunicipalityResponse response = new MunicipalityResponse(); try { Municipality addedMunicipality = unitOfWork.GetMunicipalityRepository().Create(re.ConvertToMunicipality()); unitOfWork.Save(); response.Municipality = addedMunicipality.ConvertToMunicipalityViewModel(); response.Success = true; } catch (Exception ex) { response.Municipality = new MunicipalityViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Delete([FromBody] MunicipalityViewModel Municipality) { MunicipalityResponse response = new MunicipalityResponse(); try { response = this.MunicipalityService.Delete(Municipality.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 MunicipalityResponse DeleteAll() { MunicipalityResponse response = new MunicipalityResponse(); try { using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); db.EnableExtensions(true); SqliteCommand insertCommand = new SqliteCommand(); insertCommand.Connection = db; //Use parameterized query to prevent SQL injection attacks insertCommand.CommandText = "DELETE FROM Municipalities"; try { insertCommand.ExecuteNonQuery(); } 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 MunicipalityResponse Delete(Guid identifier) { MunicipalityResponse response = new MunicipalityResponse(); try { Municipality deletedMunicipality = unitOfWork.GetMunicipalityRepository().Delete(identifier); unitOfWork.Save(); response.Municipality = deletedMunicipality.ConvertToMunicipalityViewModel(); response.Success = true; } catch (Exception ex) { response.Municipality = new MunicipalityViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public MunicipalityResponse GetMunicipality(Guid identifier) { MunicipalityResponse response = new MunicipalityResponse(); MunicipalityViewModel Municipality = new MunicipalityViewModel(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM Municipalities " + "WHERE Identifier = @Identifier;", db); selectCommand.Parameters.AddWithValue("@Identifier", identifier); SqliteDataReader query = selectCommand.ExecuteReader(); if (query.Read()) { MunicipalityViewModel dbEntry = Read(query); Municipality = dbEntry; } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.Municipality = new MunicipalityViewModel(); return(response); } db.Close(); } response.Success = true; response.Municipality = Municipality; return(response); }
private void btnSave_Click(object sender, RoutedEventArgs e) { #region Validation if (String.IsNullOrEmpty(CurrentMunicipality.Name)) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Naziv_opštine")); return; } #endregion Thread th = new Thread(() => { SaveButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke")); SaveButtonEnabled = false; CurrentMunicipality.IsSynced = false; CurrentMunicipality.Company = new CompanyViewModel() { Id = MainWindow.CurrentCompanyId }; CurrentMunicipality.CreatedBy = new UserViewModel() { Id = MainWindow.CurrentUserId }; MunicipalityResponse response = MunicipalityService.Create(CurrentMunicipality); if (!response.Success) { MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_čuvanja_na_serveruUzvičnik")); SaveButtonContent = ((string)Application.Current.FindResource("Sačuvaj")); SaveButtonEnabled = true; } if (response.Success) { MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Podaci_su_uspešno_sačuvaniUzvičnik")); SaveButtonContent = ((string)Application.Current.FindResource("Sačuvaj")); SaveButtonEnabled = true; MunicipalityCreatedUpdated(); if (IsCreateProcess) { CurrentMunicipality = new MunicipalityViewModel(); CurrentMunicipality.Identifier = Guid.NewGuid(); Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { txtMunicipalityCode.Focus(); }) ); } else { Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { if (IsPopup) { FlyoutHelper.CloseFlyoutPopup(this); } else { FlyoutHelper.CloseFlyout(this); } }) ); } } }); th.IsBackground = true; th.Start(); }