using Learun.Util;
using System;
using System.Collections.Generic;
namespace Learun.Application.AppMagager
{
///
/// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
/// Copyright (c) 2013-2018 北京泉江科技有限公司
/// 创 建:超级管理员
/// 日 期:2018-07-02 15:31
/// 描 述:App首页图片管理
///
public class DTImgBLL : DTImgIBLL
{
private DTImgService dTImgService = new DTImgService();
#region 获取数据
///
/// 获取列表数据
///
///
public IEnumerable GetList()
{
try
{
return dTImgService.GetList();
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取列表分页数据
/// 分页参数
///
///
public IEnumerable GetPageList(Pagination pagination, string queryJson)
{
try
{
return dTImgService.GetPageList(pagination, queryJson);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 获取实体数据
/// 主键
///
///
public DTImgEntity GetEntity(string keyValue)
{
try
{
return dTImgService.GetEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
#endregion
#region 提交数据
///
/// 删除实体数据
/// 主键
///
///
public void DeleteEntity(string keyValue)
{
try
{
DTImgEntity entity = GetEntity(keyValue);
if (entity != null)
{
if (!string.IsNullOrEmpty(entity.F_FileName))
{
string fileHeadImg = Config.GetValue("fileAppDTImg");
string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_Id, entity.F_FileName);
if (DirFileHelper.IsExistFile(fileImg))
{
System.IO.File.Delete(fileImg);
}
}
}
dTImgService.DeleteEntity(keyValue);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 保存实体数据(新增、修改)
/// 主键
///
///
public void SaveEntity(string keyValue, DTImgEntity entity)
{
try
{
dTImgService.SaveEntity(keyValue, entity);
}
catch (Exception ex)
{
if (ex is ExceptionEx)
{
throw;
}
else
{
throw ExceptionEx.ThrowBusinessException(ex);
}
}
}
///
/// 更新数据状态
///
/// 主键
/// 状态1启用2禁用
public void UpdateState(string keyValue, int state)
{
DTImgEntity entity = new DTImgEntity();
entity.F_EnabledMark = state;
SaveEntity(keyValue, entity);
}
#endregion
#region 扩展方法
///
/// 获取图片 当webapi与web不在同一台服务器上时,isDistributed应为true
///
///
public void GetImg(string keyValue)
{
DTImgEntity entity = GetEntity(keyValue);
string img = "";
if (entity != null)
{
if (!string.IsNullOrEmpty(entity.F_FileName))
{
string fileHeadImg = Config.GetValue("fileAppDTImg");
string fileImg = string.Format("{0}/{1}{2}", fileHeadImg, entity.F_Id, entity.F_FileName);
if (DirFileHelper.IsExistFile(fileImg))
{
img = fileImg;
FileDownHelper.DownLoadnew(img);
return;
}
}
}
else
{
img = "/Content/images/add.jpg";
}
if (string.IsNullOrEmpty(img))
{
img = "/Content/images/add.jpg";
}
FileDownHelper.DownLoad(img);
}
#endregion
}
}