191 lines
7.0 KiB
C#
191 lines
7.0 KiB
C#
using BLL;
|
||
using Model.HSSE;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Security;
|
||
using System.Web;
|
||
using System.Web.Http;
|
||
|
||
namespace WebAPI.Controllers.HSSE
|
||
{
|
||
public class TrainTestRecordController : ApiController
|
||
{
|
||
|
||
#region 根据projectId获取培训考试列表
|
||
/// <summary>
|
||
/// 根据TestPlanId获取考生及试卷列表
|
||
/// </summary>
|
||
/// <param name="projectId">项目id</param>
|
||
/// <param name="unitId">单位id(填写则为公司级)</param>
|
||
/// <param name="pageIndex"></param>
|
||
/// <returns>考试人员</returns>
|
||
public Model.ResponeData getTrainTestRecordListByProjectId(string projectId,string unitId,int pageIndex=0)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(unitId))
|
||
{
|
||
if (pageIndex==0)
|
||
{
|
||
responeData.data = APITrainTestRecordService.getTrainRecordListByProjectId(projectId);
|
||
}
|
||
else{
|
||
var getDataList = APITrainTestRecordService.getTrainRecordListByProjectId(projectId);
|
||
int pageCount = getDataList.Count;
|
||
if (pageCount > 0 && pageIndex > 0)
|
||
{
|
||
getDataList = getDataList.Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList();
|
||
}
|
||
responeData.data = new { pageCount, getDataList };
|
||
}
|
||
}
|
||
else {
|
||
if (pageIndex == 0)
|
||
{
|
||
responeData.data = APITrainTestRecordService.getTrainRecordListByUnitId(unitId);
|
||
}
|
||
else
|
||
{
|
||
var getDataList = APITrainTestRecordService.getTrainRecordListByUnitId(unitId);
|
||
int pageCount = getDataList.Count;
|
||
if (pageCount > 0 && pageIndex > 0)
|
||
{
|
||
getDataList = getDataList.Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList();
|
||
}
|
||
responeData.data = new { pageCount, getDataList };
|
||
}
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region 根据id获取培训考试
|
||
/// <summary>
|
||
/// 根据id获取培训考试
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns>培训考试</returns>
|
||
public Model.ResponeData getTrainTestRecordListById(string id)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
responeData.data = APITrainTestRecordService.getTrainRecordByTrainingId(id);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
#endregion
|
||
|
||
public static void SaveAttachFile(string dataId, string menuId, string url)
|
||
{
|
||
Model.ToDoItem toDoItem = new Model.ToDoItem
|
||
{
|
||
MenuId = menuId,
|
||
DataId = dataId,
|
||
UrlStr = url,
|
||
};
|
||
APIUpLoadFileService.SaveAttachUrl(toDoItem);
|
||
}
|
||
#region 添加取培训考试
|
||
/// <summary>
|
||
/// 添加取培训考试
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns>培训考试</returns>
|
||
[HttpPost]
|
||
public Model.ResponeData updateTrainRecord(TrainTestRecordItem item)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(item.UnitId))
|
||
{
|
||
if (string.IsNullOrEmpty(item.TrainingTestRecordId))
|
||
item.TrainingTestRecordId = Guid.NewGuid().ToString();
|
||
APITrainTestRecordService.updateTrainRecord(item);
|
||
SaveAttachFile(item.TrainingTestRecordId + "r", BLL.Const.CheckListMenuId, item.AttachUrl1);
|
||
SaveAttachFile(item.TrainingTestRecordId + "re", BLL.Const.CheckListMenuId, item.AttachUrl2);
|
||
}
|
||
else {
|
||
if (string.IsNullOrEmpty(item.TrainingTestRecordId))
|
||
item.TrainingTestRecordId = Guid.NewGuid().ToString();
|
||
APITrainTestRecordService.updateTrainRecord(item);
|
||
SaveAttachFile(item.TrainingTestRecordId + "r", BLL.Const.CheckListMenuId, item.AttachUrl1);
|
||
SaveAttachFile(item.TrainingTestRecordId + "re", BLL.Const.CheckListMenuId, item.AttachUrl2);
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
#endregion
|
||
|
||
#region 添加取培训考试(公司级)不需要传projectId
|
||
/// <summary>
|
||
/// 添加取培训考试
|
||
/// </summary>
|
||
/// <param name="item"></param>
|
||
/// <returns>培训考试</returns>
|
||
[HttpPost]
|
||
public Model.ResponeData updateTrainRecordCompany(TrainTestRecordItem item)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(item.TrainingTestRecordId))
|
||
item.TrainingTestRecordId = Guid.NewGuid().ToString();
|
||
APITrainTestRecordService.updateTrainRecord(item);
|
||
SaveAttachFile(item.TrainingTestRecordId + "r", BLL.Const.CheckListMenuId, item.AttachUrl1);
|
||
SaveAttachFile(item.TrainingTestRecordId + "re", BLL.Const.CheckListMenuId, item.AttachUrl2);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
#endregion
|
||
|
||
#region 根据unitId获取培训考试列表
|
||
/// <summary>
|
||
/// 根据unitId获取考生及试卷列表
|
||
/// </summary>
|
||
/// <param name="unitId"></param>
|
||
/// <returns>考试人员</returns>
|
||
public Model.ResponeData getTrainTestRecordListByUnitId(string unitId)
|
||
{
|
||
var responeData = new Model.ResponeData();
|
||
try
|
||
{
|
||
responeData.data = APITrainTestRecordService.getTrainRecordListByUnitId(unitId);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responeData.code = 0;
|
||
responeData.message = ex.Message;
|
||
}
|
||
return responeData;
|
||
}
|
||
#endregion
|
||
}
|
||
} |