FieldWorkClient/Services/FileUploadService.cs

59 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Hopetry.Models;
using Hopetry.Provider;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hopetry.Services
{
public class FileUploadService
{
private readonly SqlSugarScope _db;
public FileUploadService()
{
_db = SqlSugarConfig.GetSqlSugarScope();
}
// 示例:查询所有文件信息
public List<FUpload> GetAllFiles()
{
return _db.Queryable<FUpload>().ToList();
}
// 示例:添加文件信息
public bool AddFile(FUpload file)
{
return _db.Insertable(file).ExecuteCommand() > 0;
}
// 示例:更新文件信息
public bool UpdateFile(FUpload file)
{
return _db.Updateable(file).ExecuteCommand() > 0;
}
// 示例:删除文件信息
public bool DeleteFile(int id)
{
return _db.Deleteable<FUpload>().Where(f => f.Id == id).ExecuteCommand() > 0;
}
// 检查数据库是否存在,不存在则创建
public void InitDatabase()
{
_db.DbMaintenance.CreateDatabase(); // SQLite不需要创建数据库但可以用于检查
// 如果表不存在则创建
if (!_db.DbMaintenance.IsAnyTable("f_upload", false))
{
_db.CodeFirst.InitTables(typeof(FUpload));
}
}
}
}