/*
* 测试
*/
using System;
using System.Web;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using MySystem.Models.Bs;
using Library;
using LitJson;
using Microsoft.AspNetCore.Authorization;
using MySystem.Service.Bs;
using System.Linq;
namespace MySystem.Areas.Api.Controllers.v1
{
[Area("Api")]
[Route("Api/v1/[controller]/[action]")]
public class TestController : BaseController
{
public TestController(IHttpContextAccessor accessor) : base(accessor)
{
}
#region 测试方法
///
/// 产品库列表
///
///
// [HttpPost]
// [Authorize]
[Route("/main/test/all")]
public JsonResult List(string value)
{
value = PublicFunction.DesDecrypt(value);
JsonData jsonObj = JsonMapper.ToObject(value);
// Dictionary obj = new Dictionary(); //返回字段
// var anths = BaseClass.GetRightJson();
// obj.Add("AuthsTree", anths); //主token,用于刷新apiToken
List relationData = new List();
List> dataList = new List>();
var Other = new Dictionary();
int count = 0;
List> source = SysAdminService.List(relationData, "", out count, 1, 999);
foreach (Dictionary subdata in source)
{
Dictionary curData = new Dictionary();
curData.Add("Id", subdata["Id"].ToString()); //Id
curData.Add("AdminName", subdata["AdminName"].ToString()); //用户名
curData.Add("RealName", subdata["RealName"].ToString()); //名称
curData.Add("RoleId", subdata["Role"].ToString()); //角色
curData.Add("LastLoginDate", subdata["LastLoginDate"] == null ? "" : DateTime.Parse(subdata["LastLoginDate"].ToString()).ToString("yyyy-MM-dd HH:mm:ss")); //最后登录时间
dataList.Add(curData);
}
Other.Add("Count", count); //总数
int SysAdminId = 6; //系统用户Id
string AdminName = "AHHA"; //用户名
string RealName = "ABBA"; //名称
string PassWord = "123456"; //密码
string RoleId = "1"; //角色
var sysAdmin = bsdb.SysAdmin.FirstOrDefault(m => m.Id == SysAdminId) ?? new SysAdmin();
if (sysAdmin.Id > 0)
{
if (!string.IsNullOrEmpty(AdminName))
{
sysAdmin.AdminName = AdminName;
}
if (!string.IsNullOrEmpty(RealName))
{
sysAdmin.RealName = RealName;
}
if (!string.IsNullOrEmpty(PassWord))
{
sysAdmin.Password = function.MD5_32(PassWord);
}
if (!string.IsNullOrEmpty(RoleId) && RoleId != sysAdmin.Role)
{
sysAdmin.Role = RoleId;
}
}
bsdb.SaveChanges();
return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList });
}
#endregion
}
}