public EmployeeByConstructionSiteListResponse Sync(SyncEmployeeByConstructionSiteRequest request) { EmployeeByConstructionSiteListResponse response = new EmployeeByConstructionSiteListResponse(); try { response.EmployeeByConstructionSites = new List <EmployeeByConstructionSiteViewModel>(); if (request.LastUpdatedAt != null) { response.EmployeeByConstructionSites.AddRange(unitOfWork.GetEmployeeByConstructionSiteRepository() .GetEmployeeByConstructionSitesNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToEmployeeByConstructionSiteViewModelList() ?? new List <EmployeeByConstructionSiteViewModel>()); } else { response.EmployeeByConstructionSites.AddRange(unitOfWork.GetEmployeeByConstructionSiteRepository() .GetEmployeeByConstructionSites(request.CompanyId) ?.ConvertToEmployeeByConstructionSiteViewModelList() ?? new List <EmployeeByConstructionSiteViewModel>()); } response.Success = true; } catch (Exception ex) { response.EmployeeByConstructionSites = new List <EmployeeByConstructionSiteViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public EmployeeByConstructionSiteListResponse Sync(SyncEmployeeByConstructionSiteRequest request) { EmployeeByConstructionSiteListResponse response = new EmployeeByConstructionSiteListResponse(); try { response = WpfApiHandler.SendToApi <SyncEmployeeByConstructionSiteRequest, EmployeeByConstructionSiteViewModel, EmployeeByConstructionSiteListResponse>(request, "Sync"); } catch (Exception ex) { response.EmployeeByConstructionSites = new List <EmployeeByConstructionSiteViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncEmployeeByConstructionSiteRequest request) { EmployeeByConstructionSiteListResponse response = new EmployeeByConstructionSiteListResponse(); try { response = this.employeeByConstructionSiteService.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(IEmployeeByConstructionSiteService employeeByConstructionSiteService, Action <int, int> callback = null) { try { SyncEmployeeByConstructionSiteRequest request = new SyncEmployeeByConstructionSiteRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; EmployeeByConstructionSiteListResponse response = employeeByConstructionSiteService.Sync(request); if (response.Success) { toSync = response?.EmployeeByConstructionSites?.Count ?? 0; List <EmployeeByConstructionSiteViewModel> employeeByConstructionSitesFromDB = response.EmployeeByConstructionSites; using (SqliteConnection db = new SqliteConnection(SQLiteHelper.SqLiteTableName)) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM EmployeeByConstructionSites WHERE Identifier = @Identifier"; SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; foreach (var employeeByConstructionSite in employeeByConstructionSitesFromDB) { deleteCommand.Parameters.AddWithValue("@Identifier", employeeByConstructionSite.Identifier); deleteCommand.ExecuteNonQuery(); deleteCommand.Parameters.Clear(); if (employeeByConstructionSite.IsActive) { employeeByConstructionSite.IsSynced = true; insertCommand = AddCreateParameters(insertCommand, employeeByConstructionSite); 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; } }