public SectorResponse Delete(Guid identifier) { SectorResponse response = new SectorResponse(); 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 Sectors 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 SectorResponse Create(SectorViewModel sector) { SectorResponse response = new SectorResponse(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; try { insertCommand = AddCreateParameters(insertCommand, sector); 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 SectorResponse Create(SectorViewModel sector) { SectorResponse response = new SectorResponse(); try { response = WpfApiHandler.SendToApi <SectorViewModel, SectorResponse>(sector, "Create"); } catch (Exception ex) { response.Sector = new SectorViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public SectorResponse Delete(Guid identifier) { SectorResponse response = new SectorResponse(); try { SectorViewModel re = new SectorViewModel(); re.Identifier = identifier; response = WpfApiHandler.SendToApi <SectorViewModel, SectorResponse>(re, "Delete"); } catch (Exception ex) { response.Sector = new SectorViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Delete([FromBody] SectorViewModel sector) { SectorResponse response = new SectorResponse(); try { response = this.sectorService.Delete(sector.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 SectorResponse DeleteAll() { SectorResponse response = new SectorResponse(); 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 Sectors"; 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 SectorResponse Create(SectorViewModel sector) { SectorResponse response = new SectorResponse(); try { Sector addedSector = unitOfWork.GetSectorRepository().Create(sector.ConvertToSector()); unitOfWork.Save(); response.Sector = addedSector.ConvertToSectorViewModel(); response.Success = true; } catch (Exception ex) { response.Sector = new SectorViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public SectorResponse Delete(Guid identifier) { SectorResponse response = new SectorResponse(); try { Sector deletedSector = unitOfWork.GetSectorRepository().Delete(identifier); unitOfWork.Save(); response.Sector = deletedSector.ConvertToSectorViewModel(); response.Success = true; } catch (Exception ex) { response.Sector = new SectorViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public SectorResponse GetSector(Guid identifier) { SectorResponse response = new SectorResponse(); SectorViewModel sector = new SectorViewModel(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM Sectors " + "WHERE Identifier = @Identifier;", db); selectCommand.Parameters.AddWithValue("@Identifier", identifier); SqliteDataReader query = selectCommand.ExecuteReader(); if (query.Read()) { SectorViewModel dbEntry = Read(query); sector = Read(query); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.Sector = new SectorViewModel(); return(response); } db.Close(); } response.Success = true; response.Sector = sector; return(response); }
private void btnSave_Click(object sender, RoutedEventArgs e) { #region Validation if (CurrentSector.SecondCode == null) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Šifra")); return; } if (String.IsNullOrEmpty(CurrentSector.Name)) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Naziv_sektora")); return; } if (CurrentSector.Country == null) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Ime_drzave")); return; } #endregion Thread th = new Thread(() => { SaveButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke")); SaveButtonEnabled = false; CurrentSector.IsSynced = false; CurrentSector.Company = new CompanyViewModel() { Id = MainWindow.CurrentCompanyId }; CurrentSector.CreatedBy = new UserViewModel() { Id = MainWindow.CurrentUserId }; SectorResponse response = sectorService.Create(CurrentSector); 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; SectorCreatedUpdated(); if (IsCreateProcess) { CurrentSector = new SectorViewModel(); CurrentSector.Identifier = Guid.NewGuid(); Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { txtSecondCode.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(); }