using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
public static class AttachFileService
{
///
/// 添加附件存储信息
///
///
public static void AddAttachFile(Model.AttachFile attachFile)
{
Model.HJGLDB db = Funs.DB;
string newKeyID = SQLHelper.GetNewID(typeof(Model.AttachFile));
Model.AttachFile newAttachFile = new Model.AttachFile();
newAttachFile.AttachFileId = newKeyID;
newAttachFile.ToKeyId = attachFile.ToKeyId;
newAttachFile.AttachSource = attachFile.AttachSource;
newAttachFile.AttachUrl = attachFile.AttachUrl;
newAttachFile.MenuId = attachFile.MenuId;
db.AttachFile.InsertOnSubmit(newAttachFile);
db.SubmitChanges();
}
///
/// 修改附件存储信息
///
///
public static void updateAttachFile(Model.AttachFile attachFile)
{
Model.HJGLDB db = Funs.DB;
Model.AttachFile newAttachFile = db.AttachFile.FirstOrDefault(x => x.AttachFileId == attachFile.AttachFileId);
newAttachFile.ToKeyId = attachFile.ToKeyId;
newAttachFile.AttachSource = attachFile.AttachSource;
newAttachFile.AttachUrl = attachFile.AttachUrl;
newAttachFile.MenuId = attachFile.MenuId;
Funs.DB.SubmitChanges();
}
///
/// 根据对应Id删除附件信息及文件存放的物理位置
///
///
public static void DeleteAttachFile(string rootPath, string toKeyId, string menuId)
{
Model.HJGLDB db = Funs.DB;
Model.AttachFile att = db.AttachFile.FirstOrDefault(e => e.ToKeyId == toKeyId && e.MenuId == menuId);
if (att != null)
{
BLL.UploadFileService.DeleteFile(rootPath, att.AttachUrl);
db.AttachFile.DeleteOnSubmit(att);
db.SubmitChanges();
}
}
///
/// 根据对应主键和菜单获取文件信息
///
/// 对应主键
/// 对应菜单
/// 文件信息
public static Model.AttachFile GetAttachFile(string toKey,string menuId)
{
return Funs.DB.AttachFile.FirstOrDefault(e => e.ToKeyId == toKey && e.MenuId == menuId);
}
}
}