public TaxAdministrationListResponse GetTaxAdministrationsNewerThan(int companyId, DateTime?lastUpdateTime) { TaxAdministrationListResponse response = new TaxAdministrationListResponse(); try { if (lastUpdateTime != null) { response.TaxAdministrations = unitOfWork.GetTaxAdministrationRepository() .GetTaxAdministrationsNewerThan(companyId, (DateTime)lastUpdateTime) .ConvertToTaxAdministrationViewModelList(); } else { response.TaxAdministrations = unitOfWork.GetTaxAdministrationRepository() .GetTaxAdministrations(companyId) .ConvertToTaxAdministrationViewModelList(); } response.Success = true; } catch (Exception ex) { response.TaxAdministrations = new List <TaxAdministrationViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public TaxAdministrationListResponse Sync(SyncTaxAdministrationRequest request) { TaxAdministrationListResponse response = new TaxAdministrationListResponse(); try { response.TaxAdministrations = new List <TaxAdministrationViewModel>(); if (request.LastUpdatedAt != null) { response.TaxAdministrations.AddRange(unitOfWork.GetTaxAdministrationRepository() .GetTaxAdministrationsNewerThan(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToTaxAdministrationViewModelList() ?? new List <TaxAdministrationViewModel>()); } else { response.TaxAdministrations.AddRange(unitOfWork.GetTaxAdministrationRepository() .GetTaxAdministrations(request.CompanyId) ?.ConvertToTaxAdministrationViewModelList() ?? new List <TaxAdministrationViewModel>()); } response.Success = true; } catch (Exception ex) { response.TaxAdministrations = new List <TaxAdministrationViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public TaxAdministrationListResponse Sync(SyncTaxAdministrationRequest request) { TaxAdministrationListResponse response = new TaxAdministrationListResponse(); try { response = WpfApiHandler.SendToApi <SyncTaxAdministrationRequest, TaxAdministrationViewModel, TaxAdministrationListResponse>(request, "Sync"); } catch (Exception ex) { response.TaxAdministrations = new List <TaxAdministrationViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult GetTaxAdministrations(int companyId) { TaxAdministrationListResponse response = new TaxAdministrationListResponse(); try { response = taxAdministrationService.GetTaxAdministrations(companyId); } 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 JsonResult Sync([FromBody] SyncTaxAdministrationRequest request) { TaxAdministrationListResponse response = new TaxAdministrationListResponse(); try { response = this.taxAdministrationService.Sync(request); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(Json(response, new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.Indented })); }
public TaxAdministrationListResponse GetTaxAdministrations(int companyId) { TaxAdministrationListResponse response = new TaxAdministrationListResponse(); try { response.TaxAdministrations = unitOfWork.GetTaxAdministrationRepository().GetTaxAdministrations(companyId) .ConvertToTaxAdministrationViewModelList(); response.Success = true; } catch (Exception ex) { response.TaxAdministrations = new List <TaxAdministrationViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public TaxAdministrationListResponse TaxAdministrationsForPopup(int companyId, string filterString) { TaxAdministrationListResponse response = new TaxAdministrationListResponse(); List <TaxAdministrationViewModel> TaxAdministrations = new List <TaxAdministrationViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM TaxAdministrations " + "WHERE (@Name IS NULL OR @Name = '' OR Name LIKE @Name OR Name LIKE @Name) " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC " + "LIMIT @ItemsPerPage;", db); selectCommand.Parameters.AddWithValue("@Name", ((object)filterString) != null ? "%" + filterString + "%" : ""); selectCommand.Parameters.AddWithValue("@CompanyId", ((object)filterString) != null ? companyId : 0); selectCommand.Parameters.AddWithValue("@ItemsPerPage", 100); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { TaxAdministrations.Add(Read(query)); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.TaxAdministrations = new List <TaxAdministrationViewModel>(); return(response); } db.Close(); } response.Success = true; response.TaxAdministrations = TaxAdministrations; return(response); }
public TaxAdministrationListResponse GetTaxAdministrations(int companyId) { TaxAdministrationListResponse response = new TaxAdministrationListResponse(); try { response = WpfApiHandler.GetFromApi <List <TaxAdministrationViewModel>, TaxAdministrationListResponse>("GetTaxAdministrations", new Dictionary <string, string>() { { "CompanyId", companyId.ToString() } }); } catch (Exception ex) { response.TaxAdministrations = new List <TaxAdministrationViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public void Sync(ITaxAdministrationService taxAdministrationService, Action <int, int> callback = null) { try { SyncTaxAdministrationRequest request = new SyncTaxAdministrationRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; TaxAdministrationListResponse response = taxAdministrationService.Sync(request); if (response.Success) { toSync = response?.TaxAdministrations?.Count ?? 0; List <TaxAdministrationViewModel> taxAdministrationsFromDB = response.TaxAdministrations; using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM TaxAdministrations WHERE Identifier = @Identifier"; SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; foreach (var taxAdministration in taxAdministrationsFromDB) { deleteCommand.Parameters.AddWithValue("@Identifier", taxAdministration.Identifier); deleteCommand.ExecuteNonQuery(); deleteCommand.Parameters.Clear(); if (taxAdministration.IsActive) { taxAdministration.IsSynced = true; insertCommand = AddCreateParameters(insertCommand, taxAdministration); insertCommand.ExecuteNonQuery(); insertCommand.Parameters.Clear(); syncedItems++; callback?.Invoke(syncedItems, toSync); } } transaction.Commit(); } db.Close(); } } else { throw new Exception(response.Message); } } catch (Exception ex) { MainWindow.ErrorMessage = ex.Message; } }
public TaxAdministrationListResponse GetTaxAdministrationsByPage(int companyId, TaxAdministrationViewModel TaxAdministrationSearchObject, int currentPage = 1, int itemsPerPage = 50) { TaxAdministrationListResponse response = new TaxAdministrationListResponse(); List <TaxAdministrationViewModel> TaxAdministrations = new List <TaxAdministrationViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM TaxAdministrations " + "WHERE (@Code IS NULL OR @Code = '' OR Code LIKE @Code) " + "AND (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " + "AND (@CityName IS NULL OR @CityName = '' OR CityName LIKE @CityName) " + "AND (@BankName1 IS NULL OR @BankName1 = '' OR BankName1 LIKE @BankName1) " + "AND (@IBAN1 IS NULL OR @IBAN1 = '' OR IBAN1 LIKE @IBAN1) " + "AND (@SWIFT IS NULL OR @SWIFT = '' OR SWIFT LIKE @SWIFT) " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC " + "LIMIT @ItemsPerPage OFFSET @Offset;", db); selectCommand.Parameters.AddWithValue("@Code", ((object)TaxAdministrationSearchObject.SearchBy_Code) != null ? "%" + TaxAdministrationSearchObject.SearchBy_Code + "%" : ""); selectCommand.Parameters.AddWithValue("@Name", ((object)TaxAdministrationSearchObject.SearchBy_Name) != null ? "%" + TaxAdministrationSearchObject.SearchBy_Name + "%" : ""); selectCommand.Parameters.AddWithValue("@CityName", ((object)TaxAdministrationSearchObject.SearchBy_City) != null ? "%" + TaxAdministrationSearchObject.SearchBy_City + "%" : ""); selectCommand.Parameters.AddWithValue("@BankName1", ((object)TaxAdministrationSearchObject.SearchBy_Bank1) != null ? "%" + TaxAdministrationSearchObject.SearchBy_Bank1 + "%" : ""); selectCommand.Parameters.AddWithValue("@IBAN1", ((object)TaxAdministrationSearchObject.SearchBy_IBAN1) != null ? "%" + TaxAdministrationSearchObject.SearchBy_IBAN1 + "%" : ""); selectCommand.Parameters.AddWithValue("@SWIFT", ((object)TaxAdministrationSearchObject.SearchBy_SWIFT) != null ? "%" + TaxAdministrationSearchObject.SearchBy_SWIFT + "%" : ""); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); selectCommand.Parameters.AddWithValue("@ItemsPerPage", itemsPerPage); selectCommand.Parameters.AddWithValue("@Offset", (currentPage - 1) * itemsPerPage); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { TaxAdministrations.Add(Read(query)); } selectCommand = new SqliteCommand( "SELECT Count(*) " + "FROM TaxAdministrations " + "WHERE (@Code IS NULL OR @Code = '' OR Code LIKE @Code) " + "AND (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " + "AND (@CityName IS NULL OR @CityName = '' OR CityName LIKE @CityName) " + "AND (@BankName1 IS NULL OR @BankName1 = '' OR BankName1 LIKE @BankName1) " + "AND (@IBAN1 IS NULL OR @IBAN1 = '' OR IBAN1 LIKE @IBAN1) " + "AND (@SWIFT IS NULL OR @SWIFT = '' OR SWIFT LIKE @SWIFT) " + "AND CompanyId = @CompanyId;", db); selectCommand.Parameters.AddWithValue("@Code", ((object)TaxAdministrationSearchObject.SearchBy_Code) != null ? "%" + TaxAdministrationSearchObject.SearchBy_Code + "%" : ""); selectCommand.Parameters.AddWithValue("@Name", ((object)TaxAdministrationSearchObject.SearchBy_Name) != null ? "%" + TaxAdministrationSearchObject.SearchBy_Name + "%" : ""); selectCommand.Parameters.AddWithValue("@CityName", ((object)TaxAdministrationSearchObject.SearchBy_City) != null ? "%" + TaxAdministrationSearchObject.SearchBy_City + "%" : ""); selectCommand.Parameters.AddWithValue("@BankName1", ((object)TaxAdministrationSearchObject.SearchBy_Bank1) != null ? "%" + TaxAdministrationSearchObject.SearchBy_Bank1 + "%" : ""); selectCommand.Parameters.AddWithValue("@IBAN1", ((object)TaxAdministrationSearchObject.SearchBy_IBAN1) != null ? "%" + TaxAdministrationSearchObject.SearchBy_IBAN1 + "%" : ""); selectCommand.Parameters.AddWithValue("@SWIFT", ((object)TaxAdministrationSearchObject.SearchBy_SWIFT) != null ? "%" + TaxAdministrationSearchObject.SearchBy_SWIFT + "%" : ""); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); query = selectCommand.ExecuteReader(); if (query.Read()) { response.TotalItems = query.GetInt32(0); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.TaxAdministrations = new List <TaxAdministrationViewModel>(); return(response); } db.Close(); } response.Success = true; response.TaxAdministrations = TaxAdministrations; return(response); }