public LicenceTypeResponse Create(LicenceTypeViewModel licenceType) { LicenceTypeResponse response = new LicenceTypeResponse(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); SqliteCommand insertCommand = new SqliteCommand(); insertCommand.CommandText = SqlCommandInsertPart; insertCommand.Connection = db; try { insertCommand = AddCreateParameters(insertCommand, licenceType); 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 LicenceTypeResponse Delete(Guid identifier) { LicenceTypeResponse response = new LicenceTypeResponse(); 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 LicenceTypes 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 LicenceTypeResponse Create(LicenceTypeViewModel licenceType) { LicenceTypeResponse response = new LicenceTypeResponse(); try { response = WpfApiHandler.SendToApi <LicenceTypeViewModel, LicenceTypeResponse>(licenceType, "Create"); } catch (Exception ex) { response.LicenceType = new LicenceTypeViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public LicenceTypeResponse Delete(Guid identifier) { LicenceTypeResponse response = new LicenceTypeResponse(); try { LicenceTypeViewModel re = new LicenceTypeViewModel(); re.Identifier = identifier; response = WpfApiHandler.SendToApi <LicenceTypeViewModel, LicenceTypeResponse>(re, "Delete"); } catch (Exception ex) { response.LicenceType = new LicenceTypeViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Delete([FromBody] LicenceTypeViewModel licenceType) { LicenceTypeResponse response = new LicenceTypeResponse(); try { response = this.licenceTypeService.Delete(licenceType.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 LicenceTypeResponse DeleteAll() { LicenceTypeResponse response = new LicenceTypeResponse(); 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 LicenceTypes"; 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 LicenceTypeResponse Create(LicenceTypeViewModel licenceType) { LicenceTypeResponse response = new LicenceTypeResponse(); try { LicenceType addedLicenceType = unitOfWork.GetLicenceTypeRepository().Create(licenceType.ConvertToLicenceType()); unitOfWork.Save(); response.LicenceType = addedLicenceType.ConvertToLicenceTypeViewModel(); response.Success = true; } catch (Exception ex) { response.LicenceType = new LicenceTypeViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public LicenceTypeResponse Delete(Guid identifier) { LicenceTypeResponse response = new LicenceTypeResponse(); try { LicenceType deletedLicenceType = unitOfWork.GetLicenceTypeRepository().Delete(identifier); unitOfWork.Save(); response.LicenceType = deletedLicenceType.ConvertToLicenceTypeViewModel(); response.Success = true; } catch (Exception ex) { response.LicenceType = new LicenceTypeViewModel(); response.Success = false; response.Message = ex.Message; } return(response); }
public LicenceTypeResponse GetLicenceType(Guid identifier) { LicenceTypeResponse response = new LicenceTypeResponse(); LicenceTypeViewModel licenceType = new LicenceTypeViewModel(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM LicenceTypes " + "WHERE Identifier = @Identifier;", db); selectCommand.Parameters.AddWithValue("@Identifier", identifier); SqliteDataReader query = selectCommand.ExecuteReader(); if (query.Read()) { LicenceTypeViewModel dbEntry = Read(query); licenceType = dbEntry; } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.LicenceType = new LicenceTypeViewModel(); return(response); } db.Close(); } response.Success = true; response.LicenceType = licenceType; return(response); }
private void btnSave_Click(object sender, RoutedEventArgs e) { #region Validation if (String.IsNullOrEmpty(CurrentLicenceType.Category)) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Obavezno_poljeDvotačka_Ime_dozvole")); return; } #endregion Thread th = new Thread(() => { SaveButtonContent = ((string)Application.Current.FindResource("Čuvanje_u_tokuTriTacke")); SaveButtonEnabled = false; CurrentLicenceType.IsSynced = false; CurrentLicenceType.Company = new CompanyViewModel() { Id = MainWindow.CurrentCompanyId }; CurrentLicenceType.CreatedBy = new UserViewModel() { Id = MainWindow.CurrentUserId }; LicenceTypeResponse response = licenceTypeService.Create(CurrentLicenceType); 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; LicenceTypeCreatedUpdated(); if (IsCreateProcess) { CurrentLicenceType = new LicenceTypeViewModel(); CurrentLicenceType.Identifier = Guid.NewGuid(); Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { txtName.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(); txtName.Focus(); }