public ApiResult GetAll(TableTypeEnums?TableType) { ApiResult result = new ApiResult(); string message = string.Empty; try { if (TableType != 0) { using (FLDbContext db = new FLDbContext()) { List <Flow> FlowList = db.Flow.Where(t => t.TableType == TableType).OrderBy(t => t.ID).ToList(); result = ApiResult.NewSuccessJson(FlowList); } } else { message = "请选择正确的表单类型"; } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } if (!string.IsNullOrEmpty(message)) { result = ApiResult.NewErrorJson(message); } return(result); }
public bool ValidateTicket(string encryptTicket, out string message) { message = string.Empty; bool IsValid = false; try { using (FLDbContext db = new FLDbContext()) { SysUser user = db.SysUser.FirstOrDefault(t => t.Token == encryptTicket); if (user == null) { message = "身份未验证"; } else if (user.Expires == null || (user.Expires < DateTime.Now)) { message = "token过期超时,请重新登录."; } else { if (!string.IsNullOrEmpty(user.UserName) && !string.IsNullOrEmpty(user.Password)) { IsValid = true; LoginHelper.CurrentUser = user; } } } } catch (Exception ex) { message = ex.Message.ToString(); } return(IsValid); }
public ApiResult GetAll(string Name = "") { ApiResult result = new ApiResult(); string message = string.Empty; try { using (FLDbContext db = new FLDbContext()) { int total = db.Role.Where(t => t.Name.Contains(Name) && t.IsDel != true).Count(); List <Role> RoleList = db.Role.Where(t => t.Name.Contains(Name) && t.IsDel != true).ToList(); result = ApiResult.NewSuccessJson(new { Total = total, List = RoleList }); } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } if (!string.IsNullOrEmpty(message)) { result = ApiResult.NewErrorJson(message); } return(result); }
public ApiResult Add(BaseClass BaseClass) { ApiResult result = new ApiResult(); string message = string.Empty; try { using (FLDbContext db = new FLDbContext()) { if (string.IsNullOrEmpty(BaseClass.Name)) { message = "请输入基础班次名称"; goto Response; } if (db.BaseClass.FirstOrDefault(t => t.Name == BaseClass.Name && t.IsDel == true) != null) { message = "基础班次名称重复"; goto Response; } BaseClass.IsDel = false; BaseClass.CreateDate = DateTime.Now; db.BaseClass.Add(BaseClass); //添加时要验证完整性?BaseDate foreach (BaseClassUser bcu in BaseClass.BaseClassUserList) { bcu.BaseClassID = BaseClass.ID; } db.BaseClassUser.AddRange(BaseClass.BaseClassUserList); new SysLogDAO().AddLog(LogType.Success, message: "成功添加基础班次:" + BaseClass.Name); result = ApiResult.NewSuccessJson("成功添加基础班次:" + BaseClass.Name); } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } Response: if (!string.IsNullOrEmpty(message)) { //回滚 if (BaseClass.ID != 0) { try { new FLDbContext().BaseClass.Remove(new FLDbContext().BaseClass.FirstOrDefault(t => t.ID == BaseClass.ID)); new FLDbContext().BaseClassUser.RemoveRange(new FLDbContext().BaseClassUser.Where(t => t.BaseClassID == BaseClass.ID)); } catch { } } result = ApiResult.NewErrorJson(message); } return(result); }
public ApiResult GetAllTableTypeFlow(ClassTypeEnums?ClassType) { ApiResult result = new ApiResult(); string message = string.Empty; try { List <object> returnlist = new List <object>(); using (FLDbContext db = new FLDbContext()) { List <Flow> FlowList = db.Flow.ToList(); foreach (int item in Enum.GetValues(typeof(TableTypeEnums))) { returnlist.Add(new { ID = item, Name = Enum.GetName(typeof(TableTypeEnums), item), FlowList = FlowList.Where(t => t.TableType == (TableTypeEnums)item).ToList() }); } } result = ApiResult.NewSuccessJson(returnlist); } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } if (!string.IsNullOrEmpty(message)) { result = ApiResult.NewErrorJson(message); } return(result); }
public ApiResult GetAll(int RoleID = 0, string RealName = "", int pageindex = 1, int pagesize = 10) { ApiResult result = new ApiResult(); string message = string.Empty; try { using (FLDbContext db = new FLDbContext()) { var userlist = from User in db.SysUser join UserRole in db.UserRole on User.ID equals UserRole.UserID where (RoleID == 0 || UserRole.RoleID == RoleID) && User.IsAccountDisabled != true && User.RealName.Contains(RealName) select new { User }; int total = userlist.Select(t => t.User).Distinct().Count(); List <object> returnlist = new List <object>(); RoleDAO roledao = new RoleDAO(); foreach (var user in userlist.Select(t => t.User).Distinct().OrderByDescending(t => t.CreateDate).Skip((pageindex - 1) * pagesize).Take(pagesize)) { returnlist.Add(new { user.ID, user.RealName, user.UserName, user.TelNumber, user.Gender, RoleList = roledao.RoleList(user.ID) }); } result = ApiResult.NewSuccessJson(new { Total = total, List = returnlist }); } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } if (!string.IsNullOrEmpty(message)) { //回滚 result = ApiResult.NewErrorJson(message); } return(result); }
//public string AuthName { get; set; } public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext) { bool hasAccess = false; if (actionContext.Request.Headers.Authorization != null) { string token = actionContext.Request.Headers.Authorization.Scheme; //用户验证逻辑 string message = string.Empty; if (new AccountBLL().ValidateTicket(token, out message)) { hasAccess = false; //判断权限 SysUser user = LoginHelper.CurrentUser; if (user != null && user.IsAccountDisabled != true) { if (Roles.Length > 0) { using (FLDbContext db = new FLDbContext()) { List <AuthorizationRole> arlist = db.AuthorizationRole.Where(t => db.Authorization.Where(m => Roles.Contains(m.Name)).Select(m => m.ID).Contains(t.AuthorizationID)).ToList(); List <UserRole> urlist = db.UserRole.Where(t => t.UserID == user.ID).ToList(); if (arlist.FirstOrDefault(t => t.UserID == user.ID || urlist.Select(m => m.RoleID).Contains(t.RoleID.Value)) != null) { hasAccess = true; } } } else { hasAccess = true; } } if (!hasAccess) { message = "没有操作权限"; } } } if (hasAccess == false) { var content = new ApiResult { Status = ApiResultCodeType.Failure, Data = "没有操作权限", }; var response = actionContext.Response = actionContext.Response ?? new HttpResponseMessage(); response.Content = new StringContent(System.Web.Helpers.Json.Encode(content), Encoding.UTF8, "application/json"); } }
public ApiResult GetAll(ClassTypeEnums?ClassType = 0, TableTypeEnums?TableType = 0, DateTime?BeginDate = null, DateTime?EndDate = null, int pageindex = 1, int pagesize = 10) { ApiResult result = new ApiResult(); string message = string.Empty; try { using (FLDbContext db = new FLDbContext()) { BaseUtils bu = new BaseUtils(); BeginDate = bu.InitDate(BeginDate, true); EndDate = bu.InitDate(EndDate, false); int total = db.BaseDateFlow.Where(t => t.BeginDate > DbFunctions.CreateDateTime(t.BeginDate.Year, t.BeginDate.Month, t.BeginDate.Day, BeginDate.Value.Hour, BeginDate.Value.Minute, BeginDate.Value.Second) && t.EndDate < DbFunctions.CreateDateTime(t.EndDate.Year, t.EndDate.Month, t.EndDate.Day, EndDate.Value.Hour, EndDate.Value.Minute, EndDate.Value.Second) && (ClassType == 0 || t.ClassType == ClassType) && (TableType == 0 || t.TableType == TableType)).Count(); List <BaseDateFlow> bdfList = db.BaseDateFlow.Where(t => t.BeginDate > DbFunctions.CreateDateTime(t.BeginDate.Year, t.BeginDate.Month, t.BeginDate.Day, BeginDate.Value.Hour, BeginDate.Value.Minute, BeginDate.Value.Second) && t.EndDate < DbFunctions.CreateDateTime(t.EndDate.Year, t.EndDate.Month, t.EndDate.Day, EndDate.Value.Hour, EndDate.Value.Minute, EndDate.Value.Second) && (ClassType == 0 || t.ClassType == ClassType) && (TableType == 0 || t.TableType == TableType)).OrderBy(t => t.TableType).ThenBy(t => t.FlowID).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList(); List <object> returnlist = new List <object>(); foreach (BaseDateFlow bdf in bdfList) { returnlist.Add(new { bdf.ID, bdf.Name, TableType = Enum.GetName(typeof(TableTypeEnums), bdf.TableType), ClassType = Enum.GetName(typeof(ClassTypeEnums), bdf.ClassType), BeginDate = bdf.BeginDate.ToString("HH:mm"), EndDate = bdf.EndDate.ToString("HH:mm"), RemindDate = bdf.RemindDate.ToString("HH:mm"), }); } result = ApiResult.NewSuccessJson(new { Total = total, List = returnlist }); } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } if (!string.IsNullOrEmpty(message)) { result = ApiResult.NewErrorJson(message); } return(result); }
public static string GenerateToken(int userID, DateTime expires, FLDbContext db) { string token = Guid.NewGuid().ToString(); SysUser user = db.SysUser.FirstOrDefault(t => t.ID == userID); if (user != null) { user.Token = token; user.Expires = expires; db.SaveChanges(); } return(token); }
public void AddDictionaryData(Dictionary Dictionary) { DateTime dt = DateTime.Now; FLDbContext db = new FLDbContext(); foreach (DictionaryData Data in Dictionary.DataList) { Data.CreateDate = dt; Data.CreateUserID = LoginHelper.CurrentUser.ID; Data.DictionaryID = Dictionary.ID; Data.IsDel = false; db.DictionaryData.Add(Data); } db.SaveChanges(); }
public bool DictionaryValidate(List <TableData> tabledatalist) { bool result = true; using (FLDbContext db = new FLDbContext()) { foreach (TableData tabledata in tabledatalist) { TableColumn tc = db.TableColumn.FirstOrDefault(t => t.ID == tabledata.TableColumnID); if (tc.DictionaryID == null) { continue; } Dictionary dictionary = db.Dictionary.FirstOrDefault(t => t.ID == tc.DictionaryID); if (dictionary.DisplayType == DictionaryTypeEnums.单选) { //判断是否在所选的值之中 if (db.DictionaryData.FirstOrDefault(t => t.RexgexData == tabledata.Data || t.ID == Convert.ToInt32(tabledata.Data)) == null) { return(false); } } else { //判断是否满足 DictionaryData dictionarydata = db.DictionaryData.FirstOrDefault(t => t.DictionaryID == dictionary.ID); if (dictionarydata.RegexType == RegexType.特殊的一组字符) { result = new BaseUtils().GetRegex(tabledata.Data, dictionarydata.RegexType, dictionarydata.RexgexData.ToCharArray()); if (!result) { break; } } else { result = new BaseUtils().GetRegex(tabledata.Data, dictionarydata.RegexType); if (!result) { break; } } } } } return(result); }
public ApiResult Add(Dictionary Dictionary) { ApiResult result = new ApiResult(); string message = string.Empty; try { using (FLDbContext db = new FLDbContext()) { if (string.IsNullOrEmpty(Dictionary.Name)) { message = "请填写数据字典名称"; goto Response; } if (Dictionary.DataList == null || Dictionary.DataList.Count == 0) { message = "请添加数据字典内容"; goto Response; } Dictionary.CreateDate = DateTime.Now; Dictionary.IsDel = false; Dictionary.CreateUserID = LoginHelper.CurrentUser.ID; db.Dictionary.Add(Dictionary); db.SaveChanges(); new DictionaryDAO().AddDictionaryData(Dictionary); new SysLogDAO().AddLog(LogType.Success, message: "成功添加数据字典"); result = ApiResult.NewSuccessJson("成功添加数据字典"); } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } Response: if (!string.IsNullOrEmpty(message)) { result = ApiResult.NewErrorJson(message); } return(result); }
public ApiResult Add(Role Role) { ApiResult result = new ApiResult(); string message = string.Empty; try { using (FLDbContext db = new FLDbContext()) { if (string.IsNullOrEmpty(Role.Name)) { message = "请输入权限名称"; goto Response; } if (db.Role.FirstOrDefault(t => t.Name == Role.Name) != null) { message = "权限名称重复"; goto Response; } Role.IsDel = false; Role.CreateDate = DateTime.Now; db.Role.Add(Role); new SysLogDAO().AddLog(LogType.Success, message: "成功添加权限:" + Role.Name); result = ApiResult.NewSuccessJson("成功添加权限:" + Role.Name); } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } Response: if (!string.IsNullOrEmpty(message)) { result = ApiResult.NewErrorJson(message); } return(result); }
public ApiResult GetAll(string Name = "", ClassTypeEnums?ClassType = null, int pageindex = 1, int pagesize = 10) { ApiResult result = new ApiResult(); string message = string.Empty; try { using (FLDbContext db = new FLDbContext()) { int total = db.BaseClass.Where(t => t.Name.Contains(Name) && (ClassType == null || t.ClassType == ClassType) && t.IsDel != true).Count(); List <BaseClass> BaseClassList = db.BaseClass.Where(t => t.Name.Contains(Name) && (ClassType == null || t.ClassType == ClassType) && t.IsDel != true).OrderByDescending(t => t.CreateDate).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList(); List <object> returnlist = new List <object>(); List <BaseClassUser> BaseClassUserList = db.BaseClassUser.ToList(); foreach (BaseClass bc in BaseClassList) { returnlist.Add(new { bc.ID, bc.Name, ClassType = Enum.GetName(typeof(ClassTypeEnums), bc.ClassType), UserCount = BaseClassUserList.Count(t => t.BaseClassID == bc.ID) }); } result = ApiResult.NewSuccessJson(new { Total = total, List = returnlist }); } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } if (!string.IsNullOrEmpty(message)) { result = ApiResult.NewErrorJson(message); } return(result); }
public ApiResult Add(List <BaseDateFlow> BaseDateFlowList) { ApiResult result = new ApiResult(); string message = string.Empty; try { using (FLDbContext db = new FLDbContext()) { //这里要改的,要对flowid和classtype均相同的进行替换 List <Flow> FlowList = db.Flow.ToList(); foreach (BaseDateFlow bdf in BaseDateFlowList) { if (FlowList.FirstOrDefault(t => t.ID == bdf.FlowID) == null) { message = "请选择正确的班次类型或表单类型"; goto Response; } bdf.Name = FlowList.FirstOrDefault(t => t.ID == bdf.FlowID).Name + "-" + Enum.GetName(typeof(ClassTypeEnums), bdf.ClassType); } //添加时要验证完整性?BaseClass db.BaseDateFlow.AddRange(BaseDateFlowList); db.SaveChanges(); new SysLogDAO().AddLog(LogType.Success, message: "成功添加基础班次时间"); result = ApiResult.NewSuccessJson("成功添加基础班次时间"); } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } Response: if (!string.IsNullOrEmpty(message)) { result = ApiResult.NewErrorJson(message); } return(result); }
public ApiResult GetFullTableList(ClassTypeEnums ClassType) { ApiResult result = new ApiResult(); string message = string.Empty; try { List <object> returnlist = new List <object>(); using (FLDbContext db = new FLDbContext()) { List <Flow> FlowList = db.Flow.ToList(); List <BaseDateFlow> BaseDateFlowList = db.BaseDateFlow.Where(t => t.ClassType == ClassType).OrderBy(t => t.FlowID).ToList(); List <FullFlowList> FullFlowList = new List <FullFlowList>(); foreach (BaseDateFlow BaseDateFlow in BaseDateFlowList) { var userlist = from user in db.SysUser join userrole in db.UserRole on user.ID equals userrole.UserID join baseflowrole in db.BaseFlowRole on userrole.RoleID equals baseflowrole.RoleID where user.IsAccountDisabled != true && baseflowrole.FlowID == BaseDateFlow.FlowID select new { user.RealName, UserID = user.ID, //FlowName = flow.Name }; FullFlowList.Add(new FullFlowList { FlowID = BaseDateFlow.FlowID, FlowName = FlowList.FirstOrDefault(t => t.ID == BaseDateFlow.FlowID).Name, TableType = BaseDateFlow.TableType, UserList = userlist.ToList(), BeginDate = BaseDateFlow.BeginDate.ToString("HH:mm"), EndDate = BaseDateFlow.EndDate.ToString("HH:mm"), RemindDate = BaseDateFlow.RemindDate.ToString("HH:mm"), }); } FullFlowList = FullFlowList.Where(t => t.TableType == TableTypeEnums.切削液浓度点检表).ToList(); foreach (TableTypeEnums TableType in Enum.GetValues(typeof(TableTypeEnums))) { returnlist.Add(new { Name = Enum.GetName(typeof(TableTypeEnums), TableType), ID = TableType, FullFlowList = FullFlowList.Where(t => t.TableType == TableType).ToList() }); } } result = ApiResult.NewSuccessJson(returnlist); } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } if (!string.IsNullOrEmpty(message)) { result = ApiResult.NewErrorJson(message); } return(result); }
public ApiResult Add(SysUser User) { ApiResult result = new ApiResult(); string message = string.Empty; try { using (FLDbContext db = new FLDbContext()) { if (string.IsNullOrEmpty(User.UserName) || string.IsNullOrEmpty(User.Password)) { message = "请输入用户名和密码"; goto Response; } if (User.RoleList.Count == 0) { message = "请选择正确的权限"; goto Response; } if (db.SysUser.FirstOrDefault(t => t.UserName == User.UserName) != null) { message = "用户名重复"; goto Response; } User.Password = new BaseUtils().BuildPW(User.UserName, User.Password); User.CreateDate = DateTime.Now; User.IsAccountDisabled = false; db.SysUser.Add(User); db.SaveChanges(); //添加Role bool isrole = false; foreach (int roleid in User.RoleList) { Role role = db.Role.FirstOrDefault(t => t.ID == roleid); if (role != null) { isrole = true; UserRole ur = new UserRole(); ur.RoleID = roleid; ur.UserID = User.ID; db.UserRole.Add(ur); } } if (!isrole) { message = "请选择正确的权限"; goto Response; } db.SaveChanges(); //需要同步添加到企业微信 new SysLogDAO().AddLog(LogType.Success, message: "成功添加用户:" + User.RealName); result = ApiResult.NewSuccessJson("成功添加用户:" + User.RealName); } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } Response: if (!string.IsNullOrEmpty(message)) { if (User.ID != 0) { try { new FLDbContext().SysUser.Remove(new FLDbContext().SysUser.FirstOrDefault(t => t.ID == User.ID)); } catch { } } result = ApiResult.NewErrorJson(message); } return(result); }
public ApiResult GetAll(DateTime?BeginDate = null, DateTime?EndDate = null, int pageindex = 1, int pagesize = 10, ClassTypeEnums?ClassType = null) { ApiResult result = new ApiResult(); string message = string.Empty; try { BeginDate = BeginDate ?? Convert.ToDateTime("1900-01-01"); EndDate = EndDate ?? Convert.ToDateTime("2099-12-31"); using (FLDbContext db = new FLDbContext()) { var tasklist = from task in db.FLTask join taskflow in db.TaskFlow on task.ID equals taskflow.TaskID where taskflow.BeginDate >= BeginDate && taskflow.BeginDate <= EndDate && (ClassType == null || task.ClassType == ClassType) && taskflow.MaintainUserID == LoginHelper.CurrentUser.ID select new { TaskName = task.TaskName, TaskID = task.ID, BeginDate = taskflow.BeginDate, EndDate = taskflow.EndDate, RemindDate = taskflow.RemindDate, IsAudit = taskflow.IsAudit, ApplyType = taskflow.ApplyType }; int total = tasklist.Count(); List <object> returnlist = new List <object>(); TaskDAO taskdao = new TaskDAO(); foreach (var data in tasklist.OrderByDescending(t => t.EndDate).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList()) { returnlist.Add(new { TaskName = data.TaskName, TaskID = data.TaskID, BeginDate = data.BeginDate.ToString("yyyy-MM-dd HH:mm"), EndDate = data.EndDate.ToString("yyyy-MM-dd HH:mm"), RemindDate = data.RemindDate.ToString("yyyy-MM-dd HH:mm"), Status = taskdao.GetApplyTypeName(data.IsAudit, data.ApplyType) }); } result = ApiResult.NewSuccessJson(new { Total = total, List = returnlist }); } } catch { result = ApiResult.NewErrorJson("请检查网络状态或联系系统管理员"); } if (!string.IsNullOrEmpty(message)) { //回滚 result = ApiResult.NewErrorJson(message); } return(result); }
public ApiResult Add(TaskAdd TaskAdd) { ApiResult result = new ApiResult(); string message = string.Empty; Action action = () => { using (FLDbContext db = new FLDbContext()) { foreach (FLTask Task in TaskAdd.TaskList) { if (string.IsNullOrEmpty(Task.TaskName)) { message = "请填写任务名称"; goto Response; } Task.CreateDate = DateTime.Now; Task.IsDel = false; db.FLTask.Add(Task); db.SaveChanges(); if (Task.IsBaseClass == true) { //使用默认的班次 List <TaskFlow> tfList = new List <TaskFlow>(); List <Flow> FlowList = new FlowDAO().GetFlow(Task.TableType); foreach (BaseClass bs in TaskAdd.BaseClassList) { foreach (Flow Flow in FlowList) { List <BaseClassUser> bculist = db.BaseClassUser.Where(t => t.BaseClassID == bs.ID && t.FlowID == Flow.ID).ToList(); foreach (BaseClassUser bcu in bculist) { foreach (TaskFlow tf in Task.TaskFlowList) { //这里可以缓存一个bdf来提升效率 if (tf.IsBase) { BaseDateFlow bdf = db.BaseDateFlow.FirstOrDefault(t => t.FlowID == tf.FlowID); tf.BeginDate = bdf.BeginDate; tf.EndDate = bdf.EndDate; tf.RemindDate = bdf.RemindDate; } //tf.FlowID = bcu.FlowID; tf.MaintainUserID = bcu.UserID; tf.IsReminded = false; tf.MaintainUserID = bcu.UserID; tf.TaskID = Task.ID; tfList.Add(tf); } } } } db.TaskFlow.AddRange(tfList); } else { //先验证是否完整 List <Flow> flowList = new FlowDAO().GetFlow(Task.TableType); foreach (Flow flow in flowList) { if (Task.TaskFlowList.FirstOrDefault(t => t.FlowID == flow.ID) == null) { message = "请填写完整的流程"; goto Response; } } foreach (TaskFlow tf in Task.TaskFlowList) { if (tf.IsBase) { BaseDateFlow bdf = db.BaseDateFlow.FirstOrDefault(t => t.FlowID == tf.FlowID); tf.BeginDate = bdf.BeginDate; tf.EndDate = bdf.EndDate; tf.RemindDate = bdf.RemindDate; } tf.IsReminded = false; tf.TaskID = Task.ID; } db.TaskFlow.AddRange(Task.TaskFlowList); } } } new SysLogDAO().AddLog(LogType.Success, message: "成功添加任务"); result = ApiResult.NewSuccessJson("成功添加任务"); Response: if (!string.IsNullOrEmpty(message)) { //回滚 foreach (FLTask Task in TaskAdd.TaskList) { if (Task.ID != 0) { new FLDbContext().FLTask.Remove(new FLDbContext().FLTask.FirstOrDefault(t => t.ID == Task.ID)); } else { break; } } result = ApiResult.NewErrorJson(message); } }; TransactioExtension.Excute(action); return(result); }
public ApiResult Login(SysUser user) { ApiResult result = new ApiResult(); string message = string.Empty; try { using (FLDbContext db = new FLDbContext()) { if (!string.IsNullOrEmpty(user.UserName) && !string.IsNullOrEmpty(user.Password)) { string md5pw = new BaseUtils().BuildPW(user.UserName, user.Password); SysUser loginuser = db.SysUser.FirstOrDefault(t => t.UserName == user.UserName && t.Password == md5pw); if (loginuser != null) { if (loginuser.IsAccountDisabled == true) { message = "用户被限制登录,请联系管理员"; } else { DateTime now = DateTime.Now; DateTime?expires = null; //重新生成token expires = DateTime.Now.AddMinutes(60 * 24 * 7); //一周后过期 //expires = DateTime.Now.AddMinutes(1); //测试 string token = LoginHelper.GenerateToken(loginuser.ID, expires.Value, db); LoginHelper.CurrentUser = loginuser; loginuser.LastLogindate = DateTime.Now; db.SaveChanges(); //new WXDAO().SendMessage("登陆成功"); new SysLogDAO().AddLog(LogType.Success, message: "登录"); result.Data = new { RealName = loginuser.RealName, Token = token, Expires = expires, HeaderUrl = loginuser.HeaderUrl,//需要默认的头像 }; result.Status = ApiResultCodeType.Success; } } else { message = "登录失败,请检查用户名和密码"; } } else { message = "请输入用户名和密码"; } } } catch (Exception ex) { message = ex.Message.ToString(); } if (!string.IsNullOrEmpty(message)) { result = ApiResult.NewErrorJson(message); } return(result); }