public EmployeeCardListResponse Sync(SyncEmployeeCardRequest request) { EmployeeCardListResponse response = new EmployeeCardListResponse(); try { response.EmployeeCards = new List <EmployeeCardViewModel>(); if (request.LastUpdatedAt != null) { response.EmployeeCards.AddRange(unitOfWork.GetEmployeeCardRepository() .GetEmployeeCardsNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToEmployeeCardViewModelList() ?? new List <EmployeeCardViewModel>()); } else { response.EmployeeCards.AddRange(unitOfWork.GetEmployeeCardRepository() .GetEmployeeCards(request.CompanyId) ?.ConvertToEmployeeCardViewModelList() ?? new List <EmployeeCardViewModel>()); } response.Success = true; } catch (Exception ex) { response.EmployeeCards = new List <EmployeeCardViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public EmployeeCardListResponse Sync(SyncEmployeeCardRequest request) { EmployeeCardListResponse response = new EmployeeCardListResponse(); try { response = WpfApiHandler.SendToApi <SyncEmployeeCardRequest, EmployeeCardViewModel, EmployeeCardListResponse>(request, "Sync"); } catch (Exception ex) { response.EmployeeCards = new List <EmployeeCardViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncEmployeeCardRequest request) { EmployeeCardListResponse response = new EmployeeCardListResponse(); try { response = this.EmployeeCardService.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(IEmployeeCardService EmployeeCardService, Action <int, int> callback = null) { try { SyncEmployeeCardRequest request = new SyncEmployeeCardRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; EmployeeCardListResponse response = EmployeeCardService.Sync(request); if (response.Success) { toSync = response?.EmployeeCards?.Count ?? 0; List <EmployeeCardViewModel> items = response.EmployeeCards; using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM EmployeeCards WHERE Identifier = @Identifier"; SqliteCommand insertCommand = db.CreateCommand(); insertCommand.CommandText = SqlCommandInsertPart; foreach (var item in items) { deleteCommand.Parameters.AddWithValue("@Identifier", item.Identifier); deleteCommand.ExecuteNonQuery(); deleteCommand.Parameters.Clear(); if (item.IsActive) { item.IsSynced = true; insertCommand = AddCreateParameters(insertCommand, item); 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; } }