public DocumentFileListResponse Sync(SyncDocumentFileRequest request) { DocumentFileListResponse response = new DocumentFileListResponse(); try { response = WpfApiHandler.SendToApi <SyncDocumentFileRequest, List <DocumentFileViewModel>, DocumentFileListResponse>(request, "Sync"); } catch (Exception ex) { response.DocumentFiles = new List <DocumentFileViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public DocumentFileListResponse SubmitList(List <DocumentFileViewModel> toCreate) { DocumentFileListResponse response = new DocumentFileListResponse(); try { response = WpfApiHandler.SendToApi <List <DocumentFileViewModel>, DocumentFileListResponse>(toCreate, "SubmitList"); } catch (Exception ex) { response.DocumentFiles = new List <DocumentFileViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public DocumentFileListResponse Sync(SyncDocumentFileRequest request) { DocumentFileListResponse response = new DocumentFileListResponse(); try { response.DocumentFiles = unitOfWork.GetDocumentFileRepository().GetDocumentFiles(request.CompanyId, request?.LastUpdatedAt, request.CurrentPage, request.ItemsPerPage) ?.ConvertToDocumentFileViewModelList(); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncDocumentFileRequest request) { DocumentFileListResponse response = new DocumentFileListResponse(); try { response = this.documentFileService.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 JsonResult SubmitList([FromBody] List <DocumentFileViewModel> docFiles) { DocumentFileListResponse response = new DocumentFileListResponse(); try { response = this.documentFileService.SubmitList(docFiles); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(Json(response, new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.Indented })); }
public DocumentFileListResponse SubmitList(List <DocumentFileViewModel> toCreate) { DocumentFileListResponse response = new DocumentFileListResponse(); try { response.DocumentFiles = unitOfWork.GetDocumentFileRepository().SubmitList(toCreate .ConvertToDocumentFileList()) ?.ConvertToDocumentFileViewModelList(); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public void Sync(IDocumentFileService service, Action <int, int> callback = null) { try { SyncDocumentFileRequest request = new SyncDocumentFileRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); request.CurrentPage = 1; request.ItemsPerPage = 500; int toSync = 0; int syncedItems = 0; DocumentFileListResponse response = service.Sync(request); if (!response.Success) { throw new Exception(response.Message); } var items = new List <DocumentFileViewModel>(response?.DocumentFiles ?? new List <DocumentFileViewModel>()); while (items.Count() > 0) { toSync += response?.DocumentFiles?.Count ?? 0; using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); using (var transaction = db.BeginTransaction()) { SqliteCommand deleteCommand = db.CreateCommand(); deleteCommand.CommandText = "DELETE FROM DocumentFiles 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) { insertCommand = AddCreateParameters(insertCommand, item); insertCommand.ExecuteNonQuery(); insertCommand.Parameters.Clear(); syncedItems++; callback?.Invoke(syncedItems, toSync); } } transaction.Commit(); } db.Close(); } request.CurrentPage++; response = service.Sync(request); if (!response.Success) { throw new Exception(response.Message); } items = new List <DocumentFileViewModel>(response?.DocumentFiles ?? new List <DocumentFileViewModel>()); } } catch (Exception ex) { MainWindow.ErrorMessage = ex.Message; } }
public DocumentFileListResponse GetDocumentFiles(int companyId, DocumentFileViewModel searchObject) { DocumentFileListResponse response = new DocumentFileListResponse(); List <DocumentFileViewModel> Files = new List <DocumentFileViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand; if (!String.IsNullOrEmpty(searchObject?.Search_Name)) { selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM DocumentFiles " + "WHERE (@FileName IS NULL OR @FileName = '' OR Name LIKE @FileName) " + "AND (@FilterDateFrom IS NULL OR @FilterDateFrom = '' OR DATE(CreatedAt) >= DATE(@FilterDateFrom))" + "AND (@FilterDateTo IS NULL OR @FilterDateTo = '' OR DATE(CreatedAt) <= DATE(@FilterDateTo)) " + "AND (DocumentFolderPath LIKE @ParentPath) " + "AND CompanyId = @CompanyId " + "ORDER BY Name ASC ", db); selectCommand.Parameters.AddWithValue("@ParentPath", ((object)searchObject.Search_ParentPath) != null ? searchObject.Search_ParentPath + "%" : ""); selectCommand.Parameters.AddWithValue("@FileName", ((object)searchObject.Search_Name) != null ? "%" + searchObject.Search_Name + "%" : ""); selectCommand.Parameters.AddWithValue("@FilterDateFrom", ((object)searchObject?.Search_DateFrom ?? DBNull.Value)); selectCommand.Parameters.AddWithValue("@FilterDateTo", ((object)searchObject?.Search_DateTo ?? DBNull.Value)); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); } else { selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM DocumentFiles " + "WHERE (DocumentFolderPath = @ParentPath) " + "AND (@FilterDateFrom IS NULL OR @FilterDateFrom = '' OR DATE(CreatedAt) >= DATE(@FilterDateFrom))" + "AND (@FilterDateTo IS NULL OR @FilterDateTo = '' OR DATE(CreatedAt) <= DATE(@FilterDateTo)) " + "AND CompanyId = @CompanyId " + "ORDER BY Name ASC ", db); selectCommand.Parameters.AddWithValue("@ParentPath", ((object)searchObject.Search_ParentPath) != null ? searchObject.Search_ParentPath : ""); selectCommand.Parameters.AddWithValue("@FilterDateFrom", ((object)searchObject?.Search_DateFrom ?? DBNull.Value)); selectCommand.Parameters.AddWithValue("@FilterDateTo", ((object)searchObject?.Search_DateTo ?? DBNull.Value)); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); } SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { DocumentFileViewModel dbEntry = Read(query); Files.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.DocumentFiles = new List <DocumentFileViewModel>(); return(response); } db.Close(); } response.Success = true; response.DocumentFiles = Files; return(response); }