/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <SysValidTokenModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { SysValidToken entity = new SysValidToken(); entity.Id = ResultHelper.NewId; entity.Token = model.Token; entity.OverTime = model.OverTime; entity.ModifyTime = model.ModifyTime; entity.CreateTime = ResultHelper.NowTime; db.SysValidToken.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }
public virtual bool Edit(ref ValidationErrors errors, SysValidTokenModel model) { try { SysValidToken entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.Token = model.Token; entity.OverTime = model.OverTime; entity.ModifyTime = model.ModifyTime; entity.CreateTime = model.CreateTime; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual bool Create(ref ValidationErrors errors, SysValidTokenModel model) { try { SysValidToken entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new SysValidToken(); entity.Id = model.Id; entity.Token = model.Token; entity.OverTime = model.OverTime; entity.ModifyTime = model.ModifyTime; entity.CreateTime = model.CreateTime; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public override bool Create(ref ValidationErrors errors, SysValidTokenModel model) { try { SysValidToken entity = m_Rep.GetById(model.Id); if (entity != null) { //已经存在token,更新token entity.Token = model.Token; entity.ModifyTime = ResultHelper.NowTime; if (m_Rep.Edit(entity)) { return(true); } else { return(false); } } entity = new SysValidToken(); entity.Id = model.Id; entity.Token = model.Token; entity.OverTime = model.OverTime; entity.ModifyTime = model.ModifyTime; entity.CreateTime = model.CreateTime; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual SysValidTokenModel GetById(object id) { if (IsExists(id)) { SysValidToken entity = m_Rep.GetById(id); SysValidTokenModel model = new SysValidTokenModel(); model.Id = entity.Id; model.Token = entity.Token; model.OverTime = entity.OverTime; model.ModifyTime = entity.ModifyTime; model.CreateTime = entity.CreateTime; return(model); } else { return(null); } }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(SysValidTokenModel model) { ValidationErrors errors = new ValidationErrors(); try { SysValidToken entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new SysValidToken(); entity.Id = model.Id; entity.Token = model.Token; entity.OverTime = model.OverTime; entity.ModifyTime = model.ModifyTime; entity.CreateTime = model.CreateTime; if (await m_Rep.CreateAsync(entity)) { return(new Tuple <ValidationErrors, bool>(errors, true)); } else { errors.Add(Resource.InsertFail); return(new Tuple <ValidationErrors, bool>(errors, false)); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(new Tuple <ValidationErrors, bool>(errors, false)); } }
//校验用户名密码(对Session匹配,或数据库数据匹配) public static bool ValidateTicket(string encryptToken) { //解密Ticket var userName = DecryptToken(encryptToken.Trim()); SysValidTokenRepository m_Rep = new SysValidTokenRepository(new Models.DBContainer()); //对比 SysValidToken myToken = m_Rep.GetById(userName); if (myToken != null && myToken.OverTime >= ResultHelper.NowTime) { //更新过期时间 myToken.OverTime = ResultHelper.NowTime.AddDays(7); m_Rep.Edit(myToken); return(true); } else { return(false); } }