|
- using Nancy;
- using Learun.Util;
- using System.Collections.Generic;
- using Learun.Application.TwoDevelopment.EducationalAdministration;
- using static Learun.Application.WebApi.Modules.StuInfoFreshApi;
- using System;
- using System.IO;
- using Learun.Application.Base.SystemModule;
-
- namespace Learun.Application.WebApi
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 力软敏捷开发框架
- /// Copyright (c) 2013-2018 上海力软信息技术有限公司
- /// 创 建:超级管理员
- /// 日 期:2019-08-19 17:50
- /// 描 述:教师注册
- /// </summary>
-
- public class EmpInfoApi : BaseNoLoginApi
- {
- private EmpInfoIBLL empInfoIBLL = new EmpInfoBLL();
- private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
- private TeachSwitchIBLL teachSwitchIBLL = new TeachSwitchBLL();
-
- /// <summary>
- /// 注册接口
- /// <summary>
- public EmpInfoApi()
- : base("/Learun/adms/EducationalAdministration/EmpRegister")
- {
- Get["/pagelist"] = GetPageList;
- Get["/list"] = GetList;
- Get["/form"] = GetForm;
- Get["/formForNo"] = GetFormForNo;
- Post["/delete"] = DeleteForm;
- Post["/save"] = SaveForm;
- Post["/savePhoto"] = GetSavePhoto;
- Get["/registerbutton"] = RegisterButton;
- Post["/signon"] = Signon;
- }
-
- private Response Signon(dynamic _)
- {
- SignUpHelper.AddQueue("德玛西亚", "140181199110080255");
- return Success("成功");
- }
-
- #region 获取数据
-
- /// <summary>
- /// 获取页面显示列表分页数据
- /// <summary>
- /// <param name="_"></param>
- /// <returns></returns>
- public Response GetPageList(dynamic _)
- {
- ReqPageParam parameter = this.GetReqData<ReqPageParam>();
- var data = empInfoIBLL.GetPageList(parameter.pagination, parameter.queryJson);
- var jsonData = new
- {
- rows = data,
- total = parameter.pagination.total,
- page = parameter.pagination.page,
- records = parameter.pagination.records
- };
- return Success(jsonData);
- }
- /// <summary>
- /// 获取页面显示列表数据
- /// <summary>
- /// <param name="_"></param>
- /// <returns></returns>
- public Response GetList(dynamic _)
- {
- string queryJson = this.GetReqData();
- var data = empInfoIBLL.GetList(queryJson);
- return Success(data);
- }
-
-
- public Response RegisterButton(dynamic _)
- {
- var result = teachSwitchIBLL.FindFirst("js").ToString();
- return Success(result);
- }
- /// <summary>
- /// 获取表单数据
- /// <summary>
- /// <param name="_"></param>
- /// <returns></returns>
- public Response GetForm(dynamic _)
- {
- string keyValue = this.GetReqData();
- var EmpInfoData = empInfoIBLL.GetEmpInfoEntity(keyValue);
- var jsonData = new
- {
- EmpInfo = EmpInfoData,
- };
- return Success(jsonData);
- }
- /// <summary>
- /// 获取表单数据
- /// <summary>
- /// <param name="_"></param>
- /// <returns></returns>
- public Response GetFormForNo(dynamic _)
- {
- string keyValue = this.GetReqData();
- var EmpInfoData = empInfoIBLL.GetEmpInfoEntityByEmpNo(keyValue);
- var jsonData = new
- {
- EmpInfo = EmpInfoData,
- };
- return Success(jsonData);
- }
- #endregion
-
- #region 提交数据
-
-
- /// <summary>
- /// 头像
- /// </summary>
- /// <param name="_"></param>
- /// <returns></returns>
- private Response GetSavePhoto(dynamic _)
- {
- var model = this.GetReqData<PhotoModel>();
-
- var folderId = Guid.NewGuid().ToString();
- string filePath = Config.GetValue("AnnexesFile");
- string uploadDate = DateTime.Now.ToString("yyyyMMdd");
- string FileEextension = ".png";
- string fileGuid = Guid.NewGuid().ToString();
- string virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", filePath, model.account, uploadDate, fileGuid, FileEextension);
-
- //创建文件夹
- string path = Path.GetDirectoryName(virtualPath);
- Directory.CreateDirectory(path);
- AnnexesFileEntity fileAnnexesEntity = new AnnexesFileEntity();
- if (!System.IO.File.Exists(virtualPath))
- {
- //byte[] bytes = Convert.FromBase64String(model.Base64Url.Replace("data:image/jpeg;base64,", ""));
- byte[] bytes = Convert.FromBase64String(model.Base64Url.Substring(model.Base64Url.IndexOf("base64,") + 7));
- FileInfo file = new FileInfo(virtualPath);
- FileStream fs = file.Create();
- fs.Write(bytes, 0, bytes.Length);
- fs.Close();
-
- //文件信息写入数据库
- fileAnnexesEntity.F_Id = fileGuid;
- fileAnnexesEntity.F_FileName = "userphoto.png";
- fileAnnexesEntity.F_FilePath = virtualPath;
- fileAnnexesEntity.F_FileSize = bytes.Length.ToString();
- fileAnnexesEntity.F_FileExtensions = FileEextension;
- fileAnnexesEntity.F_FileType = FileEextension.Replace(".", "");
- annexesFileIBLL.SaveEntity(folderId, fileAnnexesEntity);
- }
-
- var data = new
- {
- Url = virtualPath.Substring(virtualPath.IndexOf("Resource")),
- AnnexesFileId = fileGuid
- };
-
- return Success(data);
- }
-
- /// <summary>
- /// 删除实体数据
- /// <param name="_"></param>
- /// <summary>
- /// <returns></returns>
- public Response DeleteForm(dynamic _)
- {
- string keyValue = this.GetReqData();
- empInfoIBLL.DeleteEntity(keyValue);
- return Success("删除成功!");
- }
- /// <summary>
- /// 保存实体数据(新增、修改)
- /// <param name="_"></param>
- /// <summary>
- /// <returns></returns>
- public Response SaveForm(dynamic _)
- {
- ReqFormEntity parameter = this.GetReqData<ReqFormEntity>();
- EmpInfoEntity entity = parameter.strEntity.ToObject<EmpInfoEntity>();
- empInfoIBLL.SaveEntity(this.userInfo, parameter.keyValue, entity);
- return Success("保存成功!");
- }
- #endregion
-
- #region 私有类
-
- /// <summary>
- /// 表单实体类
- /// <summary>
- private class ReqFormEntity
- {
- public string keyValue { get; set; }
- public string strEntity { get; set; }
- }
- #endregion
-
- }
- }
|