CompetitionAPI_dotnet/CompetitionAPI/Controllers/back/app/BaseHandlerController.cs

125 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Security.Cryptography;
using System.Text;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Competition.Mysql.Model;
namespace CompetitionAPI.Controllers
{
public class BaseHandlerController : Controller
{
protected JsonResult GetResult(bool _state)
{
return Json(new Result(_state, _state ? "success" : "fail"));
}
protected JsonResult GetResult(bool _state, object _data)
{
return Json(new Result(_state, _data));
}
protected JsonResult GetResult(bool _state, object _data, string _message)
{
return Json(new Result(_state, _data, _message));
}
protected JsonResult GetResult(bool _state, string _message)
{
return Json(new Result(_state, _message));
}
protected JsonResult GetResult(object _data)
{
return Json(new Result(_data == null ? false : true, _data));
}
/// <summary>
/// md5密码加密
/// </summary>
/// <param name="passWord"></param>
/// <returns></returns>
public static string GetMD5(string passWord)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] bt = Encoding.Default.GetBytes(passWord);//将待加密字符转为 字节型数组
byte[] resualt = md5.ComputeHash(bt);//将字节数组转为加密的字节数组
string pwds = BitConverter.ToString(resualt).Replace("-", "");
passWord = pwds;
return passWord;
}
public string GetValue(string key)
{
string method = context.Request.Method;
var value = context.Request.Query[key];
if (string.IsNullOrWhiteSpace(value))
{
if (method != "GET")
{
try
{
value = context.Request.Form[key];
}
catch
{
value = string.Empty;
}
}
}
return value;
}
public IFormFile GetFile(string key)
{
var file = context.Request.Form.Files[key];
return file;
}
/// <summary>
/// 内容
/// </summary>
protected HttpContext context = null;
protected IConfiguration Configuration = null;
protected void CrossDomain()
{
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
context.Response.Headers.Add("Access-Control-Allow-Headers", " x-www-form-urlencoded, Content-Type,x-requested-with");
context.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
}
static readonly object _syncRoot = new object();
/*
/// <summary>
/// 获取部门
/// </summary>
/// <returns></returns>
protected List<string> GetDeparts()
{
var parent_id = "depart";
DataService.BLL.pro_type_manage bll = new DataService.BLL.pro_type_manage();
var list = bll.GetModelList(string.Format(" parent_id = '{0}' ", parent_id));
return list.Select(s => s.type_name).ToList();
}
/// <summary>
/// 获取单位
/// </summary>
/// <returns></returns>
protected List<string> GetUnits()
{
var parent_id = "unit";
DataService.BLL.pro_type_manage bll = new DataService.BLL.pro_type_manage();
var list = bll.GetModelList(string.Format(" parent_id = '{0}' ", parent_id));
return list.Select(s => s.type_name).ToList();
}
*/
}
}