public BankListResponse GetBanksNewerThen(int companyId, DateTime?lastUpdateTime) { BankListResponse response = new BankListResponse(); try { if (lastUpdateTime != null) { response.Banks = unitOfWork.GetBankRepository() .GetBanksNewerThen(companyId, (DateTime)lastUpdateTime) .ConvertToBankViewModelList(); } else { response.Banks = unitOfWork.GetBankRepository() .GetBanks(companyId) .ConvertToBankViewModelList(); } response.Success = true; } catch (Exception ex) { response.Banks = new List <BankViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public BankListResponse Sync(SyncBankRequest request) { BankListResponse response = new BankListResponse(); try { response.Banks = new List <BankViewModel>(); if (request.LastUpdatedAt != null) { response.Banks.AddRange(unitOfWork.GetBankRepository() .GetBanksNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToBankViewModelList() ?? new List <BankViewModel>()); } else { response.Banks.AddRange(unitOfWork.GetBankRepository() .GetBanks(request.CompanyId) ?.ConvertToBankViewModelList() ?? new List <BankViewModel>()); } response.Success = true; } catch (Exception ex) { response.Banks = new List <BankViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public BankListResponse GetBanksForPopup(int companyId, string filterString) { BankListResponse response = new BankListResponse(); List <BankViewModel> Banks = new List <BankViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM Banks " + "WHERE (@Code IS NULL OR @Code = '' OR Code LIKE @Code) " + "AND (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC " + "LIMIT @ItemsPerPage;", db); selectCommand.Parameters.AddWithValue("@Code", ((object)filterString) != null ? "%" + filterString + "%" : ""); 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()) { BankViewModel dbEntry = Read(query); Banks.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.Banks = new List <BankViewModel>(); return(response); } db.Close(); } response.Success = true; response.Banks = Banks; return(response); }
public BankListResponse Sync(SyncBankRequest request) { BankListResponse response = new BankListResponse(); try { response = WpfApiHandler.SendToApi <SyncBankRequest, BankViewModel, BankListResponse>(request, "Sync"); } catch (Exception ex) { response.Banks = new List <BankViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
/// <summary> /// The list. /// </summary> /// <param name="parameters"> /// The parameters. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <BankListResponse> List(BankListRequest parameters) { IQueryable <BankEntity> listQuery = this.context.Banks; if (!string.IsNullOrEmpty(parameters.Filter.Name)) { listQuery = parameters.Filter.NameExact ? listQuery.Where(x => x.Name == parameters.Filter.Name) : listQuery.Where(x => x.Name.Contains(parameters.Filter.Name)); } if (!string.IsNullOrEmpty(parameters.Filter.Swift)) { listQuery = parameters.Filter.SwiftExact ? listQuery.Where(x => x.Name == parameters.Filter.Swift) : listQuery.Where(x => x.Swift.Contains(parameters.Filter.Swift)); } var queryResult = await listQuery.CountAsync(); var orderType = parameters.Order.IsDesc ? SortOrder.Descending : SortOrder.Ascending; var list = await listQuery .OrderByFieldBank(orderType, parameters.Order.Field) .Skip((parameters.Page - 1) * parameters.ItemsPerPage) .Take(parameters.ItemsPerPage) .Select(order => new BankOut { Code = order.Code, Name = order.Name, Country = order.Country, Url = order.Url, Swift = order.Swift, ChangeAt = order.ChangeAt, CreatedAt = order.CreatedAt }).ToListAsync(); var result = new BankListResponse { NumberOfItems = queryResult, Data = list }; return(result); }
public JsonResult GetBanks(int companyId) { BankListResponse response = new BankListResponse(); try { response = bankService.GetBanks(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] SyncBankRequest request) { BankListResponse response = new BankListResponse(); try { response = this.bankService.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 BankListResponse GetBanks(int companyId) { BankListResponse response = new BankListResponse(); try { response.Banks = unitOfWork.GetBankRepository().GetBanks(companyId) .ConvertToBankViewModelList(); response.Success = true; } catch (Exception ex) { response.Banks = new List <BankViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public BankListResponse GetBanks(int companyId) { BankListResponse response = new BankListResponse(); try { response = WpfApiHandler.GetFromApi <List <BankViewModel>, BankListResponse>("GetBanks", new Dictionary <string, string>() { { "CompanyId", companyId.ToString() } }); } catch (Exception ex) { response.Banks = new List <BankViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public BankListResponse GetBanksByPage(int companyId, BankViewModel bankSearchObject, int currentPage = 1, int itemsPerPage = 50) { BankListResponse response = new BankListResponse(); List <BankViewModel> Banks = new List <BankViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM Banks " + "WHERE (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " + "AND (@Swift IS NULL OR @Swift = '' OR Swift LIKE @Swift) " + "AND (@Country IS NULL OR @Country = '' OR CountryName LIKE @Country) " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC " + "LIMIT @ItemsPerPage OFFSET @Offset;", db); selectCommand.Parameters.AddWithValue("@Name", ((object)bankSearchObject.Search_Name) != null ? "%" + bankSearchObject.Search_Name + "%" : ""); selectCommand.Parameters.AddWithValue("@Country", ((object)bankSearchObject.Search_Country) != null ? "%" + bankSearchObject.Search_Country + "%" : ""); selectCommand.Parameters.AddWithValue("@Swift", ((object)bankSearchObject.Search_Swift) != null ? "%" + bankSearchObject.Search_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()) { BankViewModel dbEntry = Read(query); Banks.Add(dbEntry); } selectCommand = new SqliteCommand( "SELECT Count(*) " + "FROM Banks " + "WHERE (@Name IS NULL OR @Name = '' OR Name LIKE @Name) " + "AND (@Swift IS NULL OR @Swift = '' OR Swift LIKE @Swift) " + "AND (@Country IS NULL OR @Country = '' OR CountryName LIKE @Country) " + "AND CompanyId = @CompanyId;", db); selectCommand.Parameters.AddWithValue("@Name", ((object)bankSearchObject.Search_Name) != null ? "%" + bankSearchObject.Search_Name + "%" : ""); selectCommand.Parameters.AddWithValue("@Country", ((object)bankSearchObject.Search_Country) != null ? "%" + bankSearchObject.Search_Country + "%" : ""); selectCommand.Parameters.AddWithValue("@Swift", ((object)bankSearchObject.Search_Swift) != null ? "%" + bankSearchObject.Search_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.Banks = new List <BankViewModel>(); return(response); } db.Close(); } response.Success = true; response.Banks = Banks; return(response); }
public void Sync(IBankService bankService, Action <int, int> callback = null) { try { SyncBankRequest request = new SyncBankRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; BankListResponse response = bankService.Sync(request); if (response.Success) { toSync = response?.Banks?.Count ?? 0; List <BankViewModel> banksFromDB = response.Banks; using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM Banks WHERE Identifier = @Identifier"; SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; foreach (var bank in banksFromDB) { deleteCommand.Parameters.AddWithValue("@Identifier", bank.Identifier); deleteCommand.ExecuteNonQuery(); deleteCommand.Parameters.Clear(); if (bank.IsActive) { bank.IsSynced = true; insertCommand = AddCreateParameters(insertCommand, bank); 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; } }