public DocumentFolderListResponse GetDocumentFolders(int companyId, DocumentFolderViewModel searchObject, bool initialDisplay = false) { DocumentFolderListResponse response = new DocumentFolderListResponse(); List <DocumentFolderViewModel> folders = new List <DocumentFolderViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand; if (searchObject.Search_ShouldLoadSubDirectories) { selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM DocumentFolders " + "WHERE (@FolderName IS NULL OR @FolderName = '' OR Name LIKE @FolderName) " + "AND (@ParentFolderId IS NULL OR @ParentFolderId = '' OR ParentFolderId = @ParentFolderId) " + "AND CompanyId = @CompanyId " + "ORDER BY Name ASC ", db); selectCommand.Parameters.AddWithValue("@ParentFolderId", ((object)searchObject?.Search_ParentId ?? DBNull.Value)); } else { selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM DocumentFolders " + "WHERE (@FolderName IS NULL OR @FolderName = '' OR Name LIKE @FolderName) " + "AND CompanyId = @CompanyId " + "ORDER BY Name ASC ", db); } selectCommand.Parameters.AddWithValue("@FolderName", ((object)searchObject.Search_Name) != null ? "%" + searchObject.Search_Name + "%" : ""); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { DocumentFolderViewModel dbEntry = Read(query); folders.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.DocumentFolders = new List <DocumentFolderViewModel>(); return(response); } db.Close(); } response.Success = true; response.DocumentFolders = folders; return(response); }
public DocumentFolderListResponse Sync(SyncDocumentFolderRequest request) { DocumentFolderListResponse response = new DocumentFolderListResponse(); try { response = WpfApiHandler.SendToApi <SyncDocumentFolderRequest, List <DocumentFolderViewModel>, DocumentFolderListResponse>(request, "Sync"); } catch (Exception ex) { response.DocumentFolders = new List <DocumentFolderViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public DocumentFolderListResponse SubmitList(List <DocumentFolderViewModel> toCreate) { DocumentFolderListResponse response = new DocumentFolderListResponse(); try { response = WpfApiHandler.SendToApi <List <DocumentFolderViewModel>, DocumentFolderListResponse>(toCreate, "SubmitList"); } catch (Exception ex) { response.DocumentFolders = new List <DocumentFolderViewModel>(); response.Success = false; response.Message = ex.Message; } return(response); }
public DocumentFolderListResponse Sync(SyncDocumentFolderRequest request) { DocumentFolderListResponse response = new DocumentFolderListResponse(); try { response.DocumentFolders = unitOfWork.GetDocumentFolderRepository().GetDocumentFolders(request.CompanyId, request?.LastUpdatedAt, request.CurrentPage, request.ItemsPerPage) ?.ConvertToDocumentFolderViewModelList(); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public DocumentFolderListResponse SubmitList(List <DocumentFolderViewModel> toCreate) { DocumentFolderListResponse response = new DocumentFolderListResponse(); try { response.DocumentFolders = unitOfWork.GetDocumentFolderRepository().SubmitList(toCreate .ConvertToDocumentFolderList()) ?.ConvertToDocumentFolderViewModelList(); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(response); }
public JsonResult Sync([FromBody] SyncDocumentFolderRequest request) { DocumentFolderListResponse response = new DocumentFolderListResponse(); try { response = this.documentFolderService.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 <DocumentFolderViewModel> docFolders) { DocumentFolderListResponse response = new DocumentFolderListResponse(); try { response = this.documentFolderService.SubmitList(docFolders); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(Json(response, new Newtonsoft.Json.JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.Indented })); }
public DocumentFolderListResponse GetRootFolder(int companyId) { DocumentFolderListResponse response = new DocumentFolderListResponse(); List <DocumentFolderViewModel> folders = new List <DocumentFolderViewModel>(); using (SqliteConnection db = new SqliteConnection("Filename=SirmiumERPGFC.db")) { db.Open(); try { SqliteCommand selectCommand = new SqliteCommand( SqlCommandSelectPart + "FROM DocumentFolders " + "WHERE ParentFolderId IS NULL " + "AND CompanyId = @CompanyId " + "ORDER BY Name ASC ", db); selectCommand.Parameters.AddWithValue("@CompanyId", companyId); SqliteDataReader query = selectCommand.ExecuteReader(); while (query.Read()) { DocumentFolderViewModel dbEntry = Read(query); folders.Add(dbEntry); } } catch (SqliteException error) { MainWindow.ErrorMessage = error.Message; response.Success = false; response.Message = error.Message; response.DocumentFolders = new List <DocumentFolderViewModel>(); return(response); } db.Close(); } response.Success = true; response.DocumentFolders = folders; return(response); }
public void Sync(IDocumentFolderService service, Action <int, int> callback = null) { try { SyncDocumentFolderRequest request = new SyncDocumentFolderRequest(); request.CompanyId = MainWindow.CurrentCompanyId; request.LastUpdatedAt = GetLastUpdatedAt(MainWindow.CurrentCompanyId); request.CurrentPage = 1; request.ItemsPerPage = 500; int toSync = 0; int syncedItems = 0; DocumentFolderListResponse response = service.Sync(request); if (!response.Success) { throw new Exception(response.Message); } var items = new List <DocumentFolderViewModel>(response?.DocumentFolders ?? new List <DocumentFolderViewModel>()); while (items.Count() > 0) { toSync += response?.DocumentFolders?.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 DocumentFolders 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 <DocumentFolderViewModel>(response?.DocumentFolders ?? new List <DocumentFolderViewModel>()); } } catch (Exception ex) { MainWindow.ErrorMessage = ex.Message; } }