Esempio n. 1
0
        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()));
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
 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();
         }
     }
 }
Esempio n. 4
0
        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()));
        }
Esempio n. 5
0
 public static void InsertUserSubcribeLog(UserSubscribeLog userlog)
 {
     using (WeChatDbContext entity = new WeChatDbContext())
     {
         entity.UserSubscribeLogs.Add(userlog);
         entity.SaveChanges();
     }
 }
Esempio n. 6
0
 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;
     }
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
        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();
        }
Esempio n. 9
0
 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();
     }
 }
Esempio n. 10
0
        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;
        }
Esempio n. 11
0
 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);
         }
     }
 }
Esempio n. 12
0
        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())));
        }
Esempio n. 13
0
        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()));
        }
Esempio n. 14
0
 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();
         }
     }
 }
Esempio n. 15
0
 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;
         }
     }
 }
Esempio n. 16
0
 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();
     }
 }
Esempio n. 17
0
 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;
     }
 }
Esempio n. 18
0
 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;
     }
 }
Esempio n. 19
0
 public ArticleManager()
 {
     _db = new WeChatDbContext();
 }
Esempio n. 20
0
 public InitialHostDbBuilder(WeChatDbContext context)
 {
     _context = context;
 }
Esempio n. 21
0
 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();
     }
 }
Esempio n. 22
0
 public static List<string> GetActivityTypeList()
 {
     using (WeChatDbContext entity = new WeChatDbContext())
     {
         var typeList = (from item in entity.ActivityModels select item.ActivityType).Distinct().ToList();
         return typeList;
     }
 }
Esempio n. 23
0
 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();
         }
     }
 }
Esempio n. 24
0
 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;
     }
 }
Esempio n. 25
0
 public static List<ActivityChannels> GetChannelList()
 {
     using (WeChatDbContext entity = new WeChatDbContext())
     {
         var channelList = (from item in entity.ActivityChannels select item).ToList();
         return channelList;
     }
 }
Esempio n. 26
0
 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;
     }
 }
Esempio n. 27
0
 public DefaultEditionCreator(WeChatDbContext context)
 {
     _context = context;
 }
Esempio n. 28
0
 public DefaultLanguagesCreator(WeChatDbContext context)
 {
     _context = context;
 }
Esempio n. 29
0
 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();
     }
 }
Esempio n. 30
0
 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;
     }
 }
Esempio n. 31
0
 public DefaultSettingsCreator(WeChatDbContext context)
 {
     _context = context;
 }
Esempio n. 32
0
 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;
     }
 }
Esempio n. 33
0
 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;
     }
 }
Esempio n. 34
0
 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;
     }
 }
Esempio n. 35
0
 //查询中石油关注用户
 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;
         }
     }
 }
Esempio n. 36
0
 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();
     }
 }
Esempio n. 37
0
 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();
         }
     }
 }
Esempio n. 38
0
 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();
         }
     }
 }
Esempio n. 39
0
 public TenantRoleAndUserBuilder(WeChatDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
Esempio n. 40
0
 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;
 }
Esempio n. 42
0
 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; }
     }
 }
Esempio n. 43
0
 public HostRoleAndUserCreator(WeChatDbContext context)
 {
     _context = context;
 }
Esempio n. 44
0
 public DefaultTenantCreator(WeChatDbContext context)
 {
     _context = context;
 }