public PhysicalPersonDocumentListResponse Sync(SyncPhysicalPersonDocumentRequest request) { PhysicalPersonDocumentListResponse response = new PhysicalPersonDocumentListResponse(); try { response.PhysicalPersonDocuments = new List <PhysicalPersonDocumentViewModel>(); if (request.LastUpdatedAt != null) { response.PhysicalPersonDocuments.AddRange(unitOfWork.GetPhysicalPersonDocumentRepository() .GetPhysicalPersonDocumentsNewerThen(request.CompanyId, (DateTime)request.LastUpdatedAt) ?.ConvertToPhysicalPersonDocumentViewModelList() ?? new List <PhysicalPersonDocumentViewModel>()); } else { response.PhysicalPersonDocuments.AddRange(unitOfWork.GetPhysicalPersonDocumentRepository() .GetPhysicalPersonDocuments(request.CompanyId) ?.ConvertToPhysicalPersonDocumentViewModelList() ?? new List <PhysicalPersonDocumentViewModel>()); } response.Success = true; } catch (Exception ex) { response.PhysicalPersonDocuments = new List <PhysicalPersonDocumentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public PhysicalPersonDocumentListResponse GetFilteredPhysicalPersonDocuments(int companyId, PhysicalPersonDocumentViewModel filterObject) { PhysicalPersonDocumentListResponse response = new PhysicalPersonDocumentListResponse(); List <PhysicalPersonDocumentViewModel> PhysicalPersonDocuments = new List <PhysicalPersonDocumentViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + ", phys.PhysPersonName as PhysPersonName, phys.PhysPersonSurname as PhysPersonSurname " + "FROM PhysicalPersonDocuments " + "LEFT JOIN (SELECT Identifier AS PhysPersonIdentifier, Name AS PhysPersonName, Surname AS PhysPersonSurname FROM PhysicalPersons) phys ON phys.PhysPersonIdentifier = PhysicalPersonDocuments.PhysicalPersonIdentifier " + "WHERE (" + " ((@PhysicalPersonName IS NULL OR @PhysicalPersonName = '' OR PhysPersonName LIKE @PhysicalPersonName) OR (@PhysicalPersonName IS NULL OR @PhysicalPersonName = '' OR PhysPersonSurName LIKE @PhysicalPersonName)) OR " + " (@PhysicalPersonName IS NULL OR @PhysicalPersonName = '' OR Name LIKE @PhysicalPersonName) " + ") " + "AND (@DateFrom IS NULL OR @DateFrom = '' OR DATE(CreateDate) >= DATE(@DateFrom)) " + "AND (@DateTo IS NULL OR @DateTo = '' OR DATE(CreateDate) <= DATE(@DateTo)) " + "ORDER BY IsSynced, Id DESC;", db); selectCommand.Parameters.AddWithValue("@PhysicalPersonName", (String.IsNullOrEmpty(filterObject.Search_Name) ? "" : "%" + filterObject.Search_Name + "%")); selectCommand.Parameters.AddWithValue("@DateFrom", ((object)filterObject.Search_DateFrom) ?? DBNull.Value); selectCommand.Parameters.AddWithValue("@DateTo", ((object)filterObject.Search_DateTo) ?? DBNull.Value); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { PhysicalPersonDocumentViewModel dbEntry = Read(query, readForMail: true); PhysicalPersonDocuments.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.PhysicalPersonDocuments = new List <PhysicalPersonDocumentViewModel>(); return(response); } db.Close(); } response.Success = true; response.PhysicalPersonDocuments = PhysicalPersonDocuments; return(response); }
public PhysicalPersonDocumentListResponse Sync(SyncPhysicalPersonDocumentRequest request) { PhysicalPersonDocumentListResponse response = new PhysicalPersonDocumentListResponse(); try { response = WpfApiHandler.SendToApi <SyncPhysicalPersonDocumentRequest, PhysicalPersonDocumentViewModel, PhysicalPersonDocumentListResponse>(request, "Sync"); } catch (Exception ex) { response.PhysicalPersonDocuments = new List <PhysicalPersonDocumentViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncPhysicalPersonDocumentRequest request) { PhysicalPersonDocumentListResponse response = new PhysicalPersonDocumentListResponse(); try { response = this.PhysicalPersonDocumentService.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 PhysicalPersonDocumentListResponse GetPhysicalPersonDocumentsByPhysicalPerson(int companyId, Guid PhysicalPersonIdentifier) { PhysicalPersonDocumentListResponse response = new PhysicalPersonDocumentListResponse(); List <PhysicalPersonDocumentViewModel> PhysicalPersonDocuments = new List <PhysicalPersonDocumentViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM PhysicalPersonDocuments " + "WHERE PhysicalPersonIdentifier = @PhysicalPersonIdentifier " + "AND CompanyId = @CompanyId " + "ORDER BY IsSynced, Id DESC;", db); selectCommand.Parameters.AddWithValue("@PhysicalPersonIdentifier", PhysicalPersonIdentifier); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { PhysicalPersonDocumentViewModel dbEntry = Read(query); PhysicalPersonDocuments.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.PhysicalPersonDocuments = new List <PhysicalPersonDocumentViewModel>(); return(response); } db.Close(); } response.Success = true; response.PhysicalPersonDocuments = PhysicalPersonDocuments; return(response); }
public void Sync(IPhysicalPersonDocumentService physicalPersonDocumentService, Action <int, int> callback = null) { try { SyncPhysicalPersonDocumentRequest request = new SyncPhysicalPersonDocumentRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); int toSync = 0; int syncedItems = 0; PhysicalPersonDocumentListResponse response = physicalPersonDocumentService.Sync(request); if (response.Success) { toSync = response?.PhysicalPersonDocuments?.Count ?? 0; List <PhysicalPersonDocumentViewModel> items = response.PhysicalPersonDocuments; using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM PhysicalPersonDocuments 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; } }