/// <summary> /// 添加默认的需求订阅信息当新用户关注时 /// </summary> /// <param name="userId"></param> /// <returns></returns> public DemandSubscription AddDefautlSubcription(int userId) { DemandSubscription subscription = null; var conn = DBHelper.GetSqlConnection(); try { var demandCatogoryRepository = new DemandCategoryRepository(); var catogroies = demandCatogoryRepository.FindAll(); using (TransactionScope scope = new TransactionScope()) { conn.Open(); var currentTime = DateTime.Now; subscription = new DemandSubscription() { InsertedTimestamp = currentTime, IsSubscribed = true, LastPushTimestamp = currentTime, LastUpdatedTimestamp = currentTime, WeChatUserId = userId, IsEnableEmailSubscription = false, EmailAddress = string.Empty }; subscription = subscriptionDao.InsertOrUpdateSubscription(conn, subscription); if (subscription.IsNotNull() && catogroies.HasItem()) { foreach (var item in catogroies) { var subscriptionDetail = new DemandSubscriptionDetail() { InsertedTimestamp = currentTime, SubscriptionId = subscription.SubscriptionId, SubscriptionType = DemandSubscriptionType.Category.ToString(), SubscriptionValue = item.Id.ToString() }; subscriptionDao.InsertSubscriptionDetail(conn, subscriptionDetail); } } scope.Complete(); } } catch (Exception ex) { LogService.LogWexin("添加默认的需求订阅信息当新用户关注时", ex.ToString()); } finally { conn.Close(); } return subscription; }
public DemandManager() { demandRepository = new DemandRepository(); demandCategoryRepository = new DemandCategoryRepository(); }