public void Post(long subscribeUserId) { if (subscribeUserId == _currentUser.Id) { throw new LinCmsException("您无法关注自己"); } LinUser linUser = _userRepository.Select.Where(r => r.Id == subscribeUserId).ToOne(); if (linUser == null) { throw new LinCmsException("该用户不存在"); } if (!linUser.IsActive()) { throw new LinCmsException("该用户已被拉黑"); } bool any = _userSubscribeRepository.Select.Any(r => r.CreateUserId == _currentUser.Id && r.SubscribeUserId == subscribeUserId); if (any) { throw new LinCmsException("您已关注该用户"); } UserSubscribe userSubscribe = new UserSubscribe() { SubscribeUserId = subscribeUserId }; _userSubscribeRepository.Insert(userSubscribe); }
private async Task <bool> Delete(UserSubscribe record) { this.SubsctibeRepository.HardDelete(record); int result = await this.SubsctibeRepository.SaveChangesAsync(); return(result == 1); }
public async Task <bool> ManageUserSubsctibe(string userSubscribedId, string subscribeToUserId, bool isWantToSubscribe) { if (string.Compare(userSubscribedId, subscribeToUserId, true) == 0) { return(false); } UserSubscribe existSubscribe = this.GetSubscribes <UserSubscribe>(userSubscribedId, subscribeToUserId).FirstOrDefault(); if (isWantToSubscribe) { if (existSubscribe != null) { return(false); } string newId = await this.CreateAsync(userSubscribedId, subscribeToUserId); return(!string.IsNullOrEmpty(newId)); } else { if (existSubscribe == null) { return(false); } return(await this.Delete(existSubscribe)); } }
/// <summary> /// Save user and also schedule subscribed model. /// </summary> public override UserSubscribe Save(UserSubscribe entity) { if (string.IsNullOrEmpty(entity.Id)) { entity = base.Save(entity); _scheduler.ScheduleJob(ScheduleHelper.CreateTriggerEveryMin(entity, ScheduleHelper.CreateRSSJob())); } return(entity); }
public async Task <IActionResult> PostUserSubscribe([FromBody] UserSubscribe userSubscribe) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.UserSubscribe.Add(userSubscribe); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUserSubscribe", new { id = userSubscribe.Id }, userSubscribe)); }
public static ITrigger CreateTriggerEveryMin(UserSubscribe userSubscribe, IJobDetail job) { return(TriggerBuilder.Create() .ForJob(job) .UsingJobData(ScheduleConsts.USER_ID, userSubscribe.UserId) .UsingJobData(ScheduleConsts.RSS_ID, userSubscribe.RssId) .UsingJobData(ScheduleConsts.GROUP_ID, userSubscribe.GroupId) .UsingJobData(ScheduleConsts.CHECKDATE, userSubscribe.CheckDate.ToString()) .WithIdentity(userSubscribe.Id, userSubscribe.UserId) .StartNow() .WithSimpleSchedule(x => x.WithIntervalInMinutes(userSubscribe.CheckPeriod).RepeatForever()) .Build()); }
public static ITrigger CreateTriggerCronExpression(UserSubscribe userSubscribe, IJobDetail job) { return(TriggerBuilder.Create() .ForJob(job) .UsingJobData(ScheduleConsts.USER_ID, userSubscribe.UserId) .UsingJobData(ScheduleConsts.RSS_ID, userSubscribe.RssId) .UsingJobData(ScheduleConsts.GROUP_ID, userSubscribe.GroupId) .UsingJobData(ScheduleConsts.CHECKDATE, userSubscribe.CheckDate.ToString()) .WithIdentity(userSubscribe.Id, userSubscribe.UserId) .StartNow() .WithCronSchedule(userSubscribe.CronExpression) .Build()); }
private async Task <string> CreateAsync(string userSubscribedId, string subscribeToUserId) { var subscribeRow = new UserSubscribe { UserSubscribedId = userSubscribedId, SubscribeToUserId = subscribeToUserId, }; await this.SubsctibeRepository.AddAsync(subscribeRow); await this.SubsctibeRepository.SaveChangesAsync(); return(subscribeRow.Id); }
public async Task InsertUserSubscriptionAsync(Guid?tenantId, UserIdentifier identifier, string notificationName) { using (var unitOfWork = _unitOfWorkManager.Begin()) using (CurrentTenant.Change(tenantId)) { var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId) { CreationTime = Clock.Now }; await UserSubscribeRepository.InsertAsync(userSubscription); await unitOfWork.SaveChangesAsync(); } }
public async Task Post(long subscribeUserId) { if (subscribeUserId == _currentUser.Id) { throw new LinCmsException("您无法关注自己"); } LinUser linUser = _userRepository.Select.Where(r => r.Id == subscribeUserId).ToOne(); if (linUser == null) { throw new LinCmsException("该用户不存在"); } if (!linUser.IsActive()) { throw new LinCmsException("该用户已被拉黑"); } bool any = _userSubscribeRepository.Select.Any(r => r.CreateUserId == _currentUser.Id && r.SubscribeUserId == subscribeUserId); if (any) { throw new LinCmsException("您已关注该用户"); } using (IUnitOfWork unitOfWork = _unitOfWorkManager.Begin()) { using ICapTransaction capTransaction = unitOfWork.BeginTransaction(_capBus, false); UserSubscribe userSubscribe = new UserSubscribe() { SubscribeUserId = subscribeUserId }; await _userSubscribeRepository.InsertAsync(userSubscribe); await _capBus.PublishAsync("NotificationController.Post", new CreateNotificationDto() { NotificationType = NotificationType.UserLikeUser, NotificationRespUserId = subscribeUserId, UserInfoId = _currentUser.Id ?? 0, CreateTime = DateTime.Now, }); await capTransaction.CommitAsync(); } }
public virtual async Task InsertUserSubscriptionAsync( Guid?tenantId, UserIdentifier identifier, string notificationName, CancellationToken cancellationToken = default) { using (var unitOfWork = _unitOfWorkManager.Begin()) using (_currentTenant.Change(tenantId)) { var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId) { CreationTime = _clock.Now }; await _userSubscribeRepository .InsertAsync(userSubscription, cancellationToken : cancellationToken); await unitOfWork.SaveChangesAsync(cancellationToken); } }
public void Post(long subscribeUserId) { if (subscribeUserId == _currentUser.Id) { throw new LinCmsException("您无法关注自己"); } LinUser linUser = _userRepository.Select.Where(r => r.Id == subscribeUserId).ToOne(); if (linUser == null) { throw new LinCmsException("该用户不存在"); } if (!linUser.IsActive()) { throw new LinCmsException("该用户已被拉黑"); } bool any = _userSubscribeRepository.Select.Any(r => r.CreateUserId == _currentUser.Id && r.SubscribeUserId == subscribeUserId); if (any) { throw new LinCmsException("您已关注该用户"); } UserSubscribe userSubscribe = new UserSubscribe() { SubscribeUserId = subscribeUserId }; _userSubscribeRepository.Insert(userSubscribe); _capBus.Publish("NotificationController.Post", new CreateNotificationDto() { NotificationType = NotificationType.UserLikeUser, NotificationRespUserId = subscribeUserId, UserInfoId = _currentUser.Id ?? 0, CreateTime = DateTime.Now, }); }
public UserSubscribedDomainEvent(Guid invokedUserId, UserSubscribe subscribe) { InvokedUserId = invokedUserId; Subscribe = subscribe; }
/// <summary> /// 初始信息处理 /// </summary> /// <param name="hasShop"></param> public static string WriteUserInfoToCookies() { HttpContext context = HttpContext.Current; string code = HttpContext.Current.Request.QueryString["code"]; string state = HttpContext.Current.Request.QueryString["state"]; string client_id = appKey; string client_secret = appSecret; string grant_type = "authorization_code"; string redirect_uri = redirect_URL; int s = 0;//记录code获取源 //从数据库获取code if (string.IsNullOrEmpty(code)) { DataTable dt = SellersBLL.GetSellersCode(Users.Nick); if (dt != null && dt.Rows.Count > 0) { s = 1; code = dt.Rows[0]["code"].ToString(); } } #region 获取授权Code if (!string.IsNullOrEmpty(code)) { DataTable dt = SellersBLL.GetSellersCode(Users.Nick); if (dt != null && dt.Rows.Count > 0 && s == 0) { SellersBLL.UpdateSellersCode(Users.Nick, code); } else if (dt == null || dt.Rows.Count == 0) { SellersBLL.AddSellersCode(Users.Nick, code); } //获取访问令牌 string url = "https://oauth.taobao.com/token?client_id={0}&client_secret={1}&grant_type={2}&code={3}&redirect_uri={4}&scope={5}&view={6}&state={7}"; string urlS = string.Format(url, client_id, client_secret, grant_type, code, redirect_uri, "item", "web", state); string getAuthAcessToken = PostDataToUrl(urlS, urlS); if (string.IsNullOrEmpty(getAuthAcessToken)) { return(null); } //20160907 yao c IDictionary resultDic = TopUtils.ParseJson(getAuthAcessToken); context.Request.Cookies.Clear(); context.Session.Clear(); //获取卖家昵称 string nick = HttpUtility.UrlDecode(resultDic["taobao_user_nick"].ToString(), Encoding.UTF8); //这里的SessionKey就是access_token string sessionKey = resultDic["access_token"].ToString(); //获取刷新令牌,以便令牌过期时重新获取 string refresh_token = resultDic["refresh_token"].ToString(); HttpCookie cookie = new HttpCookie("Top"); cookie["nick"] = CTCRM.Common.DES.Encrypt(nick); UserSellerGetResponse userRsp = null; UserSellerGetRequest req = null; try { Sellers sellers = new Sellers(); sellers.Nick = nick; try { ITopClient client = TBManager.GetClient(); req = new UserSellerGetRequest(); req.Fields = "user_id,type"; userRsp = client.Execute(req, sessionKey); } catch (Exception ex) { userRsp = null; } sellers.Seller_Creadit = 0;//short.Parse(userRsp.User.SellerCredit.Level.ToString()); sellers.Seller_Id = userRsp.User == null? 0: userRsp.User.UserId; sellers.shopType = userRsp.User == null ? "B" : userRsp.User.Type; sellers.Created = DateTime.Now; sellers.SessionKey = sessionKey; sellers.Refresh_token = refresh_token; sellers.SellerType = "pay"; cookie["SellerId"] = sellers.Seller_Id.ToString(); //获取卖家订购信息 ArticleUserSubscribe userSub = UserSubscribe.GetDeadLineDate("ts-1811102", nick); if (userSub != null) { sellers.EndDate = userSub.Deadline.ToString(); #region 标准版一月送200条 if (userSub.ItemCode.Equals("ts-1811102-1")) { sellers.OrderVersion = "标准版一月送200条"; } #endregion #region 自动评价版 if (userSub.ItemCode.Equals("ts-1811102-2")) { sellers.OrderVersion = "自动评价版"; } #endregion #region 订单打印版 if (userSub.ItemCode.Equals("ts-1811102-3")) { sellers.OrderVersion = "订单打印版"; } #endregion #region 流量推广_6个广告位 if (userSub.ItemCode.Equals("ts-1811102-4")) { sellers.OrderVersion = "流量推广_6个广告位"; } #endregion #region 订购一年送3000条短信 if (userSub.ItemCode.Equals("ts-1811102-5")) { sellers.OrderVersion = "订购一年送3000条短信"; } #endregion cookie["Deadline"] = userSub.Deadline.ToString();//比如:2016-07-04 00:00:00 cookie["OrderVersion"] = CTCRM.Common.DES.Encrypt(sellers.OrderVersion); } SellersDAL objDal = new SellersDAL(); if (!SellersDAL.GetList(sellers)) { sellers.CreatedDate = DateTime.Now;//记录卖家的第一次登陆系统时间 sellers.OrderDate = DateTime.Now.ToShortDateString(); objDal.Add(sellers); if (!objDal.AddSellerRecords(sellers.Nick, sellers.OrderVersion, userSub.Deadline.ToString(), "新订")) { File.WriteAllText(@"D:\log\" + nick + "_订购.txt", "新订失败"); } } else { string sellerEndDate = SellersDAL.GetSellerEndDate(nick); sellers.UpdateDate = DateTime.Now;//记录卖家最近一次登陆系统时间 File.WriteAllText(@"D:\log\" + nick + "_shijianOld.txt", sellerEndDate); bool sss = SellersDAL.Update(sellers); File.WriteAllText(@"D:\log\" + nick + "_更新.txt", sss.ToString()); //判断卖家是否续费软件 File.WriteAllText(@"D:\log\" + nick + "_shijianNew.txt", sellers.EndDate); if (sellers.EndDate != sellerEndDate) { if (sellers.OrderVersion == "订购一年送3000条短信") { File.WriteAllText(@"D:\log\" + nick + "_dinggou.txt", sellers.OrderVersion); MsgPackage obj = new MsgPackage(); obj.PackageName = "店铺管家短信套餐(淘宝)3000条"; obj.Type = "永久有效"; obj.SellerNick = nick; obj.Price = 0; obj.PerPrice = "0"; obj.Rank = "短信套餐(赠送)"; obj.OrderDate = DateTime.Now; obj.PayStatus = true; bool dingg = MsgBLL.AddMsgPackage(obj); File.WriteAllText(@"D:\log\" + nick + "_tianjia.txt", dingg.ToString()); DataTable dtDuanxin = MsgBLL.GetSellerMsgTrans(nick); if (dtDuanxin != null && dtDuanxin.Rows.Count > 0) { obj.MsgCanUseCount = 3000 + (dtDuanxin.Rows[0]["msgCanUseCount"] == DBNull.Value ? 0 : Convert.ToInt32(dtDuanxin.Rows[0]["msgCanUseCount"])); obj.MsgTotalCount = 3000 + (dtDuanxin.Rows[0]["msgTotalCount"] == DBNull.Value ? 0 : Convert.ToInt32(dtDuanxin.Rows[0]["msgTotalCount"])); } else { obj.MsgCanUseCount = 3000; obj.MsgTotalCount = 3000; } obj.ServiceStatus = true; obj.CanUseStartDate = DateTime.Now; MsgBLL.UpdateMsgTrans(obj); } else { File.WriteAllText(@"D:\log\" + nick + "_dinggou.txt", sellers.OrderVersion); MsgPackage obj = new MsgPackage(); obj.PackageName = "店铺管家短信套餐(淘宝)200条"; obj.Type = "永久有效"; obj.SellerNick = nick; obj.Price = 0; obj.PerPrice = "0"; obj.Rank = "短信套餐(赠送)"; obj.OrderDate = DateTime.Now; obj.PayStatus = true; bool dingg = MsgBLL.AddMsgPackage(obj); File.WriteAllText(@"D:\log\" + nick + "_tianjia.txt", dingg.ToString()); DataTable dtDuanxin = MsgBLL.GetSellerMsgTrans(nick); if (dtDuanxin != null && dtDuanxin.Rows.Count > 0) { obj.MsgCanUseCount = 200 + (dtDuanxin.Rows[0]["msgCanUseCount"] == DBNull.Value ? 0 : Convert.ToInt32(dtDuanxin.Rows[0]["msgCanUseCount"])); obj.MsgTotalCount = 200 + (dtDuanxin.Rows[0]["msgTotalCount"] == DBNull.Value ? 0 : Convert.ToInt32(dtDuanxin.Rows[0]["msgTotalCount"])); } else { obj.MsgCanUseCount = 200; obj.MsgTotalCount = 200; } obj.ServiceStatus = true; obj.CanUseStartDate = DateTime.Now; MsgBLL.UpdateMsgTrans(obj); } if (!objDal.AddSellerRecords(sellers.Nick, sellers.OrderVersion, userSub.Deadline.ToString(), "续订")) { File.WriteAllText(@"D:\log\" + nick + "_订购.txt", "续订失败"); } } } } catch (Exception ex) { //ExceptionReporter.WriteLog(userRsp.ErrMsg, ex, ExceptionPostion.TopApi, ExceptionRank.urgency); } cookie["sess"] = sessionKey; cookie.Expires = DateTime.Now.AddDays(1d); context.Response.Cookies.Add(cookie); return("1"); } else //Code为空的情况下 { return("0"); } #endregion }
public int GetUserSubandPush() { //用户Email和邮件内容 string useremail = ""; string mailcontent = ""; //在数据库中读取角色与用户信息 var context = new ApplicationDbContext(); List <ApplicationUser> allUsers = context.Users.ToList(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new ApplicationDbContext())); //获得管理员角色 ICollection <IdentityUserRole> Adminrole = roleManager.FindByName("Admin").Users; //获得等级不同角色 ICollection <IdentityUserRole> Secrole = roleManager.FindByName("Sec").Users; foreach (var item in allUsers) //轮询用户 { int sec = 0; bool flag = false; useremail = item.Email; if (useremail == "*****@*****.**" || item.EmailConfirmed == false) //if (item.EmailConfirmed == false) { continue; } foreach (var rolea in Adminrole) //是否管理员 { var find = string.Compare(rolea.UserId, item.Id); //依次查询 if (find == 0) { sec = 1; //若管理员,则等级不同 flag = true; break; } } if (!flag) { foreach (var rolea in Secrole) //是否等级不同 { var find = string.Compare(rolea.UserId, item.Id); //依次查询 if (find == 0) { sec = 1; //若等级不同,则终止 break; } } } string id = item.Id; UserSubscribe us = new UserSubscribe(); XapianLogic xl = new XapianLogic(); List <UserSubscribe.SubStruct> lus = new List <UserSubscribe.SubStruct>(); string str = CrawlConfigValue + id + @".config"; us.ShowSubXml(str, out lus); //查看该用户是否有订阅 if (lus.Count == 0) { continue; } else { foreach (var word in lus) { string tmp = xl.SearchForPush(word.SearchWord, sec, word.AddTime); //检查数据库内容 if (tmp != null || tmp != "") { mailcontent = mailcontent + tmp; //获取内容更新 } } } us.UpdateSubNodeonlytime(str); //更新订阅查询时间 if (mailcontent == "") //检查是否有内容,无内容不推送 { Console.WriteLine("no update"); continue; } PushFunction.PushFunction ppf = new PushFunction.PushFunction(); ppf.GetInfandPush(useremail, mailcontent); //按照用户邮箱和内容推送 } return(1); }