using EC.App.AutoWeight.Photo;
using learun.util;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
namespace EC.Web.Areas.AutoWeight.Controllers
{
///
/// 汽车衡
/// Copyright (c) 2019-present 汽车衡
/// 创建人:lxc
/// 日 期: 2020-11-05 12:03:48
/// 描 述: 照片表 aw_photo
///
[Area("AutoWeight")]
public class PhotoController : MvcControllerBase
{
private readonly PhotoIBll _bll;
public PhotoController(PhotoIBll bll)
{
_bll = bll;
}
#region 视图功能
/////
///// 视图
/////
/////
//[HttpGet]
//public IActionResult Index()
//{
// return View();
//}
/////
///// 视图
/////
/////
//[HttpGet]
//public IActionResult Form()
//{
// return View();
//}
#endregion 视图功能
#region 获取数据
/////
///// 获取主表aw_photo的所有列表数据
/////
///// 查询参数,json字串
/////
//[HttpGet]
//[AjaxOnly]
//public async Task GetList(string queryJson)
//{
// var list = await _bll.GetList(queryJson);
// return Success(list);
//}
/////
///// 获取主表aw_photo的分页列表数据
/////
///// 分页参数
///// 查询参数,json字串
/////
//[HttpGet]
//[AjaxOnly]
//public async Task GetPageList(string pagination, string queryJson)
//{
// var pageObj = pagination.ToObject();
// var list = await _bll.GetPageList(pageObj, queryJson);
// var jsonData = new
// {
// rows = list,
// pageObj.total,
// pageObj.page,
// pageObj.records
// };
// return Success(jsonData);
//}
/////
///// 获取表单数据
/////
///// 主键
/////
//[HttpGet]
//[AjaxOnly]
//public async Task GetForm(string keyValue)
//{
// var photoEntity = await _bll.GetEntity(keyValue);
// var jsonData = new
// {
// photoEntity
// };
// return Success(jsonData);
//}
//#endregion 获取数据
//#region 提交数据
/////
///// 删除表单数据
/////
/////
/////
//[HttpPost]
//[AjaxOnly]
//public async Task DeleteForm(string keyValue)
//{
// await _bll.Delete(keyValue);
// return SuccessInfo("删除成功!");
//}
/////
///// 新增,更新
/////
///// 主键值
///// aw_photo实体数据
/////
//[HttpPost]
//[AjaxOnly]
//public async Task SaveForm(string keyValue, PhotoEntity photoEntity)
//{
// var res = await _bll.SaveEntity(keyValue, photoEntity);
// return Success("保存成功!", res);
//}
#endregion 获取数据
#region 扩展方法
///
/// 获取图片文件
///
/// 图片序号
///
[HttpGet]
public async Task GetImg(string keyValue)
{
var photoEntity = await _bll.GetEntity(new { SerialNumber = keyValue });
if (photoEntity != null && !string.IsNullOrEmpty(photoEntity.Path) && System.IO.File.Exists(photoEntity.Path))
{
var arr = FileHelper.Read(photoEntity.Path);
return File(arr, "application/octet-stream", System.IO.Path.GetFileName(photoEntity.Path));
}
else
{
var arr = FileHelper.ReadRoot("/img/photoNoFind.jpg");
return File(arr, "application/octet-stream", "photoNoFind.jpg");
}
}
#endregion 扩展方法
}
}