public async Task <RouletteModel> CreateNewRoulette() { var roulettes = await _redisRepository.Read("Roulettes"); if (roulettes == null) { roulettes = emptyRoulettes(); } else { int countRoulettes = roulettes.Count() + 1; RouletteModel roulette = new RouletteModel { id = countRoulettes, open = false }; roulettes.Add(roulette); } await _redisRepository.Add("Roulettes", roulettes); return(roulettes.FirstOrDefault(x => x.id == roulettes.Count())); }
public async Task <Contest> GetContestById(int id) { var contest = await RedisRepository.Get <Contest>(ContestsKey + id); if (contest != null) { return(contest); } contest = await Db.Contests.Where(c => c.Id == id).FirstOrDefaultAsync(); await RedisRepository.Add(ContestsKey + id, contest); return(contest); }
public async Task <IEnumerable <Contest> > GetAllContests() { var contests = await RedisRepository.Get <IEnumerable <Contest> >(ContestsKey); if (contests != null) { return(contests); } contests = await Db.Contests.ToListAsync(); await RedisRepository.Add(ContestsKey, contests); return(contests); }
public ServiceResult Create([Required(ErrorMessage = "手机号不能为空")] string num, int validSeconds, [Required(ErrorMessage = "IP地址不能为空")] string ipAddress, int repeatSeconds = 60) { if (!_isDebug) { var isIpCheckLimit = IpCheckLimit(ipAddress); if (isIpCheckLimit) { return(ServiceResult.IsFailed("该IP地址发送次数已达上限")); } } var isNotRepeat = _redisRepository.Add(RepeatKey.Fmt(num), "1", repeatSeconds); if (!isNotRepeat) { return(ServiceResult.IsFailed($"{repeatSeconds}秒内不能重复发送")); } var code = _redisRepository.GetOrAdd(Key.Fmt(num), CreateCode, validSeconds); if (code.IsNullOrWhiteSpace()) { return(ServiceResult.IsFailed("验证码生成失败")); } _mongoRepository.Add(new SmsRecord { Content = code, PhoneNum = num, SendTime = DateTime.Now, IpAddress = ipAddress }); if (_isDebug) { return(ServiceResult.IsSuccess("发送成功")); } var sendResult = _smsService.SendSms(num, new { code }); if (sendResult.Failed) { return(sendResult); } return(ServiceResult.IsSuccess("发送成功")); }
public User Add(User user) { return(_repository.Add(user)); }