internal IResponseMessage GetByTag(string content) { var wxArticles = new List <ResponseMessageNews.Article>(); using (var db = new WeChatDbContext()) { var items = from item in db.Articles where item.Tags.Contains(content) orderby item.Published descending select item; if (items.Count() == 0) { return(null); } foreach (var item in items.Take(10)) { var wxArticle = new ResponseMessageNews.Article { Description = item.Description, Title = item.Title, PicUrl = new Uri(item.PicUrl), Url = new Uri(item.Url) }; wxArticles.Add(wxArticle); } } return(new ResponseMessageNews(wxArticles.ToArray())); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); bool isInitDb = Boolean.Parse(ConfigurationManager.AppSettings["initdb"].ToString()); if (!isInitDb) { using (var context = new WeChatDbContext()) { if (!context.Database.Exists()) { // Create the SimpleMembership database without Entity Framework migration schema ((IObjectContextAdapter)context).ObjectContext.CreateDatabase(); } } } WebSecurity.InitializeDatabaseConnection("WeChatConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); //if (!isInitDb) //{ // Configuration objConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); // AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection("appSettings"); // //Edit // if (objAppsettings != null) // { // objAppsettings.Settings["initdb"].Value = "true"; // objConfig.Save(); // } //} WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); }
public static void UpdateUser(WeChatUser user) { using (WeChatDbContext entity = new WeChatDbContext()) { var weChatUser = (from item in entity.WeChatUsers where item.OpenId == user.OpenId orderby item.WeChatUserId descending select item).FirstOrDefault(); if (weChatUser != null) { entity.Entry(weChatUser).State = System.Data.Entity.EntityState.Modified; weChatUser.Subscribe = user.Subscribe; weChatUser.LastUpdateStateTime = DateTime.Now; if (user.Subscribe == 1) { weChatUser.City = user.City; weChatUser.Country = user.Country; weChatUser.HeadImgUrl = user.HeadImgUrl; weChatUser.Language = user.Language; weChatUser.NickName = user.NickName; weChatUser.Province = user.Province; weChatUser.LastSubscribeChannel = user.LastSubscribeChannel; weChatUser.Sex = user.Sex; } entity.SaveChanges(); } } }
public IResponseMessage GetByPublishDate(string content) { var wxArticles = new List <ResponseMessageNews.Article>(); using (var db = new WeChatDbContext()) { var items = from item in db.Articles where item.Published == content orderby item.Published descending select item; if (items.Count() == 0) { return(new ResponseMessageText("无此日期的文章,请尝试其他")); } foreach (var item in items) { var wxArticle = new ResponseMessageNews.Article { Description = item.Description, Title = item.Title, PicUrl = new Uri(item.PicUrl), Url = new Uri(item.Url) }; wxArticles.Add(wxArticle); } } return(new ResponseMessageNews(wxArticles.ToArray())); }
public static void InsertUserSubcribeLog(UserSubscribeLog userlog) { using (WeChatDbContext entity = new WeChatDbContext()) { entity.UserSubscribeLogs.Add(userlog); entity.SaveChanges(); } }
public static List<WeChatUser> GetUserList(int topNumber) { using (WeChatDbContext entity = new WeChatDbContext()) { var userList = (from item in entity.WeChatUsers orderby item.WeChatUserId ascending select item).Take(topNumber).ToList(); return userList; } }
public static List<WeChatUser> GetNoInfoUsers() { //List<WeChatUser> users = new List<WeChatUser>(); using (WeChatDbContext entity = new WeChatDbContext()) { var myusers = (from item in entity.WeChatUsers where (item.Subscribe == 1) && (item.NickName == null) select item).ToList(); return myusers; } //return users; }
public static void SeedHostDb(WeChatDbContext context) { context.SuppressAutoSetTenantId = true; // Host seed new InitialHostDbBuilder(context).Create(); // Default tenant seed (in host database). new DefaultTenantBuilder(context).Create(); new TenantRoleAndUserBuilder(context, 1).Create(); }
public string GetChannelList() { using (WeChatDbContext entity = new WeChatDbContext()) { var channelList = (from item in entity.QRCodes orderby item.QRCodeId descending select item).ToList(); StringBuilder returnString = new StringBuilder(); foreach (var item in channelList) { returnString.Append(JsonConvert.SerializeObject(new { sub_channel_name = item.Title, sub_channel_code = item.QRCodeId + "_" + item.QRValue })); } return returnString.ToString(); } }
public static string GetAccessToken() { string newAccessToken = String.Empty; int weChatExpiresIn = 0; using (WeChatDbContext entity = new WeChatDbContext()) { var accesstoken = (from item in entity.AccessTokens orderby item.AccessTokenId descending select item).FirstOrDefault(); if (accesstoken == null) { WebClient wc = new WebClient(); byte[] data = null; data = wc.DownloadData(String.Format(WeChatWebAPI.GetAccessToken, appId, appSecret)); string strWebData = Encoding.Default.GetString(data); var accessTokenModel = (JObject)JsonConvert.DeserializeObject(strWebData); newAccessToken = accessTokenModel["access_token"].ToString(); weChatExpiresIn = Int32.Parse(accessTokenModel["expires_in"].ToString()); AccessToken at = new AccessToken(); at.AccessTokenStr = newAccessToken; at.ExpiresIn = weChatExpiresIn; at.LastUpdateTime = DateTime.Now; entity.AccessTokens.Add(at); entity.SaveChanges(); } else { newAccessToken = accesstoken.AccessTokenStr; TimeSpan expires_in = DateTime.Now - accesstoken.LastUpdateTime; if ((expires_in.TotalMinutes * 60) > (accesstoken.ExpiresIn - 100)) { WebClient wc = new WebClient(); byte[] data = null; data = wc.DownloadData(String.Format(WeChatWebAPI.GetAccessToken, appId, appSecret)); string strWebData = Encoding.Default.GetString(data); var accessTokenModel = (JObject)JsonConvert.DeserializeObject(strWebData); newAccessToken = accessTokenModel["access_token"].ToString(); weChatExpiresIn = Int32.Parse(accessTokenModel["expires_in"].ToString()); entity.Entry(accesstoken).State = System.Data.Entity.EntityState.Modified; accesstoken.AccessTokenStr = newAccessToken; accesstoken.ExpiresIn = weChatExpiresIn; accesstoken.LastUpdateTime = DateTime.Now; entity.SaveChanges(); } } } return newAccessToken; }
public static void InsertNewSubscribeUser(WeChatUser user) { using (WeChatDbContext entity = new WeChatDbContext()) { var olduser = (from item in entity.WeChatUsers where item.OpenId == user.OpenId select item).SingleOrDefault(); if (olduser == null) { entity.WeChatUsers.Add(user); entity.SaveChanges(); } else { UpdateUser(user); } } }
public IResponseMessage GetAllTags() { var tags = new HashSet <string>(); using (var db = new WeChatDbContext()) { var query = from item in db.Articles select item.Tags; foreach (var item in query) { var split = item.Split(' '); foreach (var tag in split) { tags.Add(tag); } } } return(new ResponseMessageText(string.Join(" ", tags.ToArray()))); }
public IResponseMessage GetTop() { var wxArticles = new List <ResponseMessageNews.Article>(); using (var db = new WeChatDbContext()) { var items = from item in db.Articles orderby item.Published descending select item; foreach (var item in items.Take(5)) { var wxArticle = new ResponseMessageNews.Article { Description = item.Description, Title = item.Title, PicUrl = new Uri(item.PicUrl), Url = new Uri(item.Url) }; wxArticles.Add(wxArticle); } } return(new ResponseMessageNews(wxArticles.ToArray())); }
public static void CancelOrder(int orderid, int userid, string username) { using (WeChatDbContext entity = new WeChatDbContext()) { var order = (from item in entity.SysWorkOrder where item.SysWorkOrderId == orderid select item).SingleOrDefault(); if (order != null) { entity.Entry(order).State = System.Data.Entity.EntityState.Modified; order.CurrentStatus = "qx"; SysWorkOrderLog wol = new SysWorkOrderLog(); wol.CreateTime = DateTime.Now; wol.Description = "操作人:" + username + ",取消了保修请求"; wol.OperateUserId = userid; wol.SysWorkOrderId = orderid; entity.SysWorkOrderLog.Add(wol); entity.SaveChanges(); } } }
public static bool IsCouponCodeValidated(string couponCode) { using (WeChatDbContext entity = new WeChatDbContext()) { var coupon = (from item in entity.ActivityModels where item.CouponCode == couponCode select item).FirstOrDefault(); if (coupon == null) { return false; } else { return true; } } }
public static void InsertActivityCodeList(List<ActivityModels> codeList) { using (WeChatDbContext entity = new WeChatDbContext()) { //var coupon = (from item in entity.ActivityModels select item).SingleOrDefault(); foreach (var code in codeList) { entity.ActivityModels.Add(code); } entity.SaveChanges(); } }
public static List<SysWorkOrderLog> GetOrderLogList(int orderId) { using (WeChatDbContext entity = new WeChatDbContext()) { var orderloglist = (from item in entity.SysWorkOrderLog where item.SysWorkOrderId == orderId select item).ToList(); return orderloglist; } }
public static int GetUserMessagePageCount() { using (WeChatDbContext entity = new WeChatDbContext()) { int pageCount = (from item in entity.UserMessages orderby item.UserMessageId descending select item.UserMessageId).Count(); return pageCount; } }
public ArticleManager() { _db = new WeChatDbContext(); }
public InitialHostDbBuilder(WeChatDbContext context) { _context = context; }
public static string GetSuplierListJsonString() { using (WeChatDbContext entity = new WeChatDbContext()) { var suplierlist = (from item in entity.Supliers select item).ToList(); StringBuilder returnString = new StringBuilder(); returnString.Append("{\"items\":["); foreach (var item in suplierlist) { returnString.Append("{"); returnString.Append("\"name\":"); returnString.Append("\"" + item.Name + "\","); returnString.Append("\"address\":"); returnString.Append("\"" + item.Address + "\","); returnString.Append("\"cellphone\":"); returnString.Append("\"" + item.PhoneNumber + "\","); returnString.Append("\"mobile\":"); returnString.Append("\"" + item.MobileNumber + "\","); returnString.Append("\"contact\":"); returnString.Append("\"" + item.ContactName + "\","); returnString.Append("\"mobile\":"); returnString.Append("\"" + item.MobileNumber + "\","); returnString.Append("\"longitude\":"); returnString.Append("\"" + item.Longitude + "\","); returnString.Append("\"latitude\":"); returnString.Append("\"" + item.Latitude + "\""); returnString.Append("},"); } if (returnString.Length > 1) { returnString.Remove(returnString.Length - 1, 1); } returnString.Append("]}"); return returnString.ToString(); } }
public static List<string> GetActivityTypeList() { using (WeChatDbContext entity = new WeChatDbContext()) { var typeList = (from item in entity.ActivityModels select item.ActivityType).Distinct().ToList(); return typeList; } }
public static void UpdateCouponCustomerInfo(ActivityModels am) { using (WeChatDbContext entity = new WeChatDbContext()) { var coupon = (from item in entity.ActivityModels where item.CouponCode == am.CouponCode select item).SingleOrDefault(); if (coupon != null) { entity.Entry(coupon).State = System.Data.Entity.EntityState.Modified; coupon.ActivityName = am.ActivityName; coupon.CellPhone = am.CellPhone; coupon.CustomerName = am.CustomerName; coupon.Description = am.Description; coupon.IsCancel = am.IsCancel; coupon.IsRevisited = am.IsRevisited; coupon.IsUsed = am.IsUsed; entity.SaveChanges(); } } }
public static ActivityChannels GetChannelById(int channelid) { using (WeChatDbContext entity = new WeChatDbContext()) { var codeChannel = (from item in entity.ActivityChannels where item.ActivityChannelsId == channelid select item).SingleOrDefault(); return codeChannel; } }
public static List<ActivityChannels> GetChannelList() { using (WeChatDbContext entity = new WeChatDbContext()) { var channelList = (from item in entity.ActivityChannels select item).ToList(); return channelList; } }
public static List<ActivityModels> GetCodeList(string codetype) { using (WeChatDbContext entity = new WeChatDbContext()) { var codeList = (from item in entity.ActivityModels where item.ActivityType == codetype select item).ToList(); return codeList; } }
public DefaultEditionCreator(WeChatDbContext context) { _context = context; }
public DefaultLanguagesCreator(WeChatDbContext context) { _context = context; }
public string ChannelList() { using (WeChatDbContext entity = new WeChatDbContext()) { var channelList = (from item in entity.QRCodes orderby item.QRCodeId descending select item).ToList(); StringBuilder returnString = new StringBuilder(); returnString.Append("["); foreach (var item in channelList) { returnString.Append(JsonConvert.SerializeObject(new { sub_channel_name = item.Title, sub_channel_code = "weixinqrcode_" + item.QRValue }) + ","); } if (returnString.Length > 0) { returnString.Remove(returnString.Length - 1, 1); } returnString.Append("]"); Response.ContentType = "application/json;charset=UTF-8"; return returnString.ToString(); } }
public static ActivityModels GetAMByCouponCode(string couponCode) { using (WeChatDbContext entity = new WeChatDbContext()) { var am = (from item in entity.ActivityModels where item.CouponCode == couponCode select item).FirstOrDefault(); return am; } }
public DefaultSettingsCreator(WeChatDbContext context) { _context = context; }
public static List<SysWorkOrder> GetOrderList() { using (WeChatDbContext entity = new WeChatDbContext()) { var list = (from item in entity.SysWorkOrder orderby item.CreateTime descending select item).ToList(); return list; } }
public static List<UserMessage> GetUserMessageList(int page, int pageSize) { using (WeChatDbContext entity = new WeChatDbContext()) { var umList = (from item in entity.UserMessages orderby item.UserMessageId descending select item).Skip((page - 1) * pageSize).Take(pageSize).ToList(); return umList; } }
public static SysWorkOrder GetSysWorkOrder(int orderid) { using (WeChatDbContext entity = new WeChatDbContext()) { var order = (from item in entity.SysWorkOrder where item.SysWorkOrderId == orderid select item).SingleOrDefault(); return order; } }
//查询中石油关注用户 public static UserSubscribeLog GetUserSubcribeLogInfo(string openId) { using (WeChatDbContext entity = new WeChatDbContext()) { var userlog = (from item in entity.UserSubscribeLogs where item.OpenId == openId orderby item.UserSubcirbeLogId descending select item).FirstOrDefault(); if ((userlog != null) && (userlog.Subcribe == 1) && (userlog.Channel >= 8) && (userlog.Channel <= 27)) { return userlog; } else { return null; } } }
public static void InsertActivityCode(ActivityModels codeModel) { using (WeChatDbContext entity = new WeChatDbContext()) { //var coupon = (from item in entity.ActivityModels select item).SingleOrDefault(); entity.ActivityModels.Add(codeModel); entity.SaveChanges(); } }
public static void AddCodeChannel(ActivityChannels c) { using (WeChatDbContext entity = new WeChatDbContext()) { var channel = (from item in entity.ActivityChannels where (item.ChannelName == c.ChannelName) && (item.ChannelUrl == c.ChannelUrl) select item).SingleOrDefault(); if (channel == null) { entity.ActivityChannels.Add(c); entity.SaveChanges(); } } }
public static void EditCodeChannel(ActivityChannels c) { using (WeChatDbContext entity = new WeChatDbContext()) { var channel = (from item in entity.ActivityChannels where item.ActivityChannelsId == c.ActivityChannelsId select item).SingleOrDefault(); if (channel != null) { entity.Entry(channel).State = System.Data.Entity.EntityState.Modified; channel.ChannelName = c.ChannelName; channel.ChannelUrl = c.ChannelUrl; channel.KeyWords = c.KeyWords; entity.SaveChanges(); } } }
public TenantRoleAndUserBuilder(WeChatDbContext context, int tenantId) { _context = context; _tenantId = tenantId; }
public static SysMyUsers GetUserInfoById(int userId) { using (WeChatDbContext entity = new WeChatDbContext()) { var user = (from item in entity.SysUsers where item.SysMyUsersId == userId select item).SingleOrDefault(); return user; } }
public DefaultTenantBuilder(WeChatDbContext context) { _context = context; }
public static SysMyUsers CheckSysUser(string userName, string passWord) { using (WeChatDbContext entity = new WeChatDbContext()) { var user = (from item in entity.SysUsers where (item.LoginName == userName) && (item.PassWord == passWord) select item).SingleOrDefault(); if (user != null) { return user; } else { return null; } } }
public HostRoleAndUserCreator(WeChatDbContext context) { _context = context; }
public DefaultTenantCreator(WeChatDbContext context) { _context = context; }