public EmployeeByBusinessPartnerListResponse Sync(SyncEmployeeByBusinessPartnerRequest request) { EmployeeByBusinessPartnerListResponse response = new EmployeeByBusinessPartnerListResponse(); try { response.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>(); if (request.LastUpdatedAt != null) { response.EmployeeByBusinessPartners.AddRange(unitOfWork.GetEmployeeByBusinessPartnerRepository() .GetEmployeeByBusinessPartnersNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToEmployeeByBusinessPartnerViewModelList() ?? new List <EmployeeByBusinessPartnerViewModel>()); } else { response.EmployeeByBusinessPartners.AddRange(unitOfWork.GetEmployeeByBusinessPartnerRepository() .GetEmployeeByBusinessPartners(request.CompanyId) ?.ConvertToEmployeeByBusinessPartnerViewModelList() ?? new List <EmployeeByBusinessPartnerViewModel>()); } response.Success = true; } catch (Exception ex) { response.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public EmployeeByBusinessPartnerListResponse Sync(SyncEmployeeByBusinessPartnerRequest request) { EmployeeByBusinessPartnerListResponse response = new EmployeeByBusinessPartnerListResponse(); try { response = WpfApiHandler.SendToApi <SyncEmployeeByBusinessPartnerRequest, EmployeeByBusinessPartnerViewModel, EmployeeByBusinessPartnerListResponse>(request, "Sync"); } catch (Exception ex) { response.EmployeeByBusinessPartners = new List <EmployeeByBusinessPartnerViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncEmployeeByBusinessPartnerRequest request) { EmployeeByBusinessPartnerListResponse response = new EmployeeByBusinessPartnerListResponse(); try { response = this.employeeByBusinessPartnerService.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(IEmployeeByBusinessPartnerService employeeByBusinessPartnerService, Action <int, int> callback = null) { try { SyncEmployeeByBusinessPartnerRequest request = new SyncEmployeeByBusinessPartnerRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; EmployeeByBusinessPartnerListResponse response = employeeByBusinessPartnerService.Sync(request); if (response.Success) { toSync = response?.EmployeeByBusinessPartners?.Count ?? 0; List <EmployeeByBusinessPartnerViewModel> employeeByBusinessPartnersFromDB = response.EmployeeByBusinessPartners; using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM EmployeeByBusinessPartners WHERE Identifier = @Identifier"; SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; foreach (var employeeByBusinessPartner in employeeByBusinessPartnersFromDB) { deleteCommand.Parameters.AddWithValue("@Identifier", employeeByBusinessPartner.Identifier); deleteCommand.ExecuteNonQuery(); deleteCommand.Parameters.Clear(); if (employeeByBusinessPartner.IsActive) { employeeByBusinessPartner.IsSynced = true; insertCommand = AddCreateParameters(insertCommand, employeeByBusinessPartner); 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; } }