public async Task <bool> AddOrUpdate(ParamUserInfo param) { var entity = param.Id <= 0 ? Context.Users.Attach(new User()).Entity : await Context.Users.SingleAsync(x => x.UserId == param.UserId && x.Id == param.Id && x.Status != 2); if (param.Id <= 0) { entity.Name = param.Name; entity.Pwd = BeeUtils.GetMD5(param.Pwd); entity.UserId = param.UserId; entity.CreateDate = DateTime.Now; entity.LastUpdate = DateTime.Now; Context.Users.Add(entity); } else { entity.Name = param.Name; entity.Status = param.Status; entity.LastUpdate = DateTime.Now; Context.Users.Update(entity); } return((await Context.SaveChangesAsync()) > 0); }
public async Task <IActionResult> GetUpdate([FromQuery] ParamConfig param) { string sign = string.Empty; if (!string.IsNullOrEmpty(param.AppId)) { sign = await _service.GetAppSign(param.AppId); } if (!param.IsValidate(sign)) { return(Unauthorized()); } var list = await _service.GetAllPublishs(); var temp = (from item in list where item.AppId.Equals(param.AppId) && item.EnvId.Equals(param.Env) select item).ToList(); var lastPublish = temp.OrderByDescending(x => x.PublishTimespan).FirstOrDefault(); await _service.SaveRequest(new EntityReq { AppEnv = param.Env, AppId = param.AppId, ClientIp = GetClientIp(), FirstDate = DateTime.Now, LastDate = DateTime.Now, LastConfigDate = lastPublish == null ? DateTime.MinValue : BeeUtils.ConvertToDateTime(lastPublish.PublishTimespan) }); if (lastPublish == null) { return(StatusCode(202)); } if (lastPublish.PublishTimespan > param.Lastupdate) { Dictionary <string, string> dicConfig = new Dictionary <string, string>(); var configs = JsonConvert.DeserializeObject <List <EntityConfig> >(lastPublish.Data); configs.ForEach(item => { dicConfig.Add(item.ConfigId, item.ConfigValue); }); return(Ok(new DtoBeeConfig { BeeConfigAppId = param.AppId, BeeConfigData = dicConfig, BeeConfigEnvironment = param.Env, BeeConfigLastUpdate = lastPublish.PublishTimespan })); } return(StatusCode(304)); }
public async Task <RpsUser> GetUser(string userId, string pwd) { string passWord = BeeUtils.GetMD5(pwd); var entity = await Context.Users.SingleAsync(x => x.UserId == userId && x.Pwd == passWord && x.Status == 0); return(new RpsUser() { Id = entity.Id, UserId = entity.UserId, Name = entity.Name }); }
public async Task <bool> ResetPassWord(ParamUsetRestPwdInfo param) { if (param.Id <= 0) { return(false); } string sourcePassword = BeeUtils.GetMD5(param.SourcePassword); string resetPassword = BeeUtils.GetMD5(param.ResetPassword); var entity = await Context.Users.SingleAsync(x => x.UserId == param.UserId && x.Pwd == sourcePassword && x.Status == 0); entity.Pwd = resetPassword; entity.LastUpdate = DateTime.Now; Context.Users.Update(entity); return((await Context.SaveChangesAsync()) > 0); }
/// <summary> /// 每分钟执行一次刷新配置信息 /// </summary> /// <param name="obj"></param> private static void Refresh(object obj) { var cacheContent = string.Empty; if (!File.Exists(_CacheFilePath)) { using (File.Create(_CacheFilePath)) { } } else { using (var reader = new StreamReader(_CacheFilePath, System.Text.Encoding.UTF8)) { cacheContent = reader.ReadToEnd(); } } DtoBeeConfig localConfig = new DtoBeeConfig { BeeConfigAppId = _BeeConfigAppId, BeeConfigEnvironment = _BeeConfigEnv, BeeConfigLastUpdate = 0 }; if (!string.IsNullOrWhiteSpace(cacheContent)) { localConfig = JsonConvert.DeserializeObject <DtoBeeConfig>(cacheContent); _BeeConfigKeyValues = JsonConvert.DeserializeObject <ConcurrentDictionary <string, string> >(JsonConvert.SerializeObject(localConfig.BeeConfigData)); } var tempCurrent = DateTime.Now.ToUniversalTime().ToString("yyyyMMddhhmmss"); var sign = BeeUtils.GetMD5($"{localConfig.BeeConfigAppId}_{localConfig.BeeConfigEnvironment}_{localConfig.BeeConfigLastUpdate}_{_BeeSecret}_{tempCurrent}"); var tempApiUrl = $"{_BeeApiUrl}?appid={localConfig.BeeConfigAppId}&env={localConfig.BeeConfigEnvironment}&lastupdate={localConfig.BeeConfigLastUpdate}&sign={sign}¤t={tempCurrent}"; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(tempApiUrl); request.Timeout = 5000; request.BeginGetResponse(new AsyncCallback(FinishWebRequest), new AsyncRequestState() { Request = request, Config = localConfig }); } catch { //不处理异常 } }
public async Task <bool> AddOrUpdate(ParamConfigInfo param) { var entity = param.Id > 0 ? Context.Configs.Single(x => x.Id == param.Id) : Context.Configs.Attach(new Config()).Entity; entity.ConfigValue = param.ConfigValue; entity.ConfigDesc = param.ConfigDesc; entity.LastUpdate = DateTime.Now; entity.LastTimespan = BeeUtils.ConvertToTimeStamp(DateTime.Now); if (param.Id <= 0) { entity.ConfigId = param.ConfigId; entity.AppId = param.AppId; entity.EnvId = param.EnvId; entity.CreateDate = DateTime.Now; Context.Configs.Add(entity); } else { Context.Configs.Update(entity); } return((await Context.SaveChangesAsync()) > 0); }