public BusinessPartnerInstitutionListResponse Sync(SyncBusinessPartnerInstitutionRequest request) { BusinessPartnerInstitutionListResponse response = new BusinessPartnerInstitutionListResponse(); try { response.BusinessPartnerInstitutions = new List <BusinessPartnerInstitutionViewModel>(); if (request.LastUpdatedAt != null) { response.BusinessPartnerInstitutions.AddRange(unitOfWork.GetBusinessPartnerInstitutionRepository() .GetBusinessPartnerInstitutionsNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToBusinessPartnerInstitutionViewModelList() ?? new List <BusinessPartnerInstitutionViewModel>()); } else { response.BusinessPartnerInstitutions.AddRange(unitOfWork.GetBusinessPartnerInstitutionRepository() .GetBusinessPartnerInstitutions(request.CompanyId) ?.ConvertToBusinessPartnerInstitutionViewModelList() ?? new List <BusinessPartnerInstitutionViewModel>()); } response.Success = true; } catch (Exception ex) { response.BusinessPartnerInstitutions = new List <BusinessPartnerInstitutionViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public BusinessPartnerInstitutionListResponse Sync(SyncBusinessPartnerInstitutionRequest request) { BusinessPartnerInstitutionListResponse response = new BusinessPartnerInstitutionListResponse(); try { response = WpfApiHandler.SendToApi <SyncBusinessPartnerInstitutionRequest, BusinessPartnerInstitutionViewModel, BusinessPartnerInstitutionListResponse>(request, "Sync"); } catch (Exception ex) { response.BusinessPartnerInstitutions = new List <BusinessPartnerInstitutionViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncBusinessPartnerInstitutionRequest request) { BusinessPartnerInstitutionListResponse response = new BusinessPartnerInstitutionListResponse(); try { response = this.businessPartnerInstitutionService.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 void Sync(IBusinessPartnerInstitutionService BusinessPartnerInstitutionService, Action <int, int> callback = null) { try { SyncBusinessPartnerInstitutionRequest request = new SyncBusinessPartnerInstitutionRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; BusinessPartnerInstitutionListResponse response = BusinessPartnerInstitutionService.Sync(request); if (response.Success) { toSync = response?.BusinessPartnerInstitutions?.Count ?? 0; List <BusinessPartnerInstitutionViewModel> businessPartnerInstitutionsFromDB = response.BusinessPartnerInstitutions; using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM BusinessPartnerInstitutions WHERE Identifier = @Identifier"; SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; foreach (var businessPartnerInstitution in businessPartnerInstitutionsFromDB) { deleteCommand.Parameters.AddWithValue("@Identifier", businessPartnerInstitution.Identifier); deleteCommand.ExecuteNonQuery(); deleteCommand.Parameters.Clear(); if (businessPartnerInstitution.IsActive) { businessPartnerInstitution.IsSynced = true; insertCommand = AddCreateParameters(insertCommand, businessPartnerInstitution); 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; } }