public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";

            string UserID, ShareUrl;
            int    shareinfoid;

            UserID      = context.Request.Form["UserID"];   //context.Request.QueryString["UserID"]; //
            ShareUrl    = context.Request.Form["ShareUrl"]; //context.Request.QueryString["ShareUrl"];//
            shareinfoid = int.Parse(weitang.StringExtensions.GetNumber(ShareUrl.Substring(ShareUrl.LastIndexOf('/') + 1)).ToString());

            Pageinexinfo   sharerindex = new Pageinexinfo();
            int            sharecounts;
            WechatEntities wechat = new WechatEntities();

            sharecounts = wechat.ShareLogs.Where(a => a.userID == UserID && a.shareUrl == ShareUrl).ToList().Count;
            sharerindex = wechat.Pageinexinfo.Where(a => a.shareinfoID == shareinfoid).FirstOrDefault();

            //
            string result = JsonConvert.SerializeObject(new ApiResponse
            {
                r = "1",
                d = new
                {
                    sharenums    = sharecounts,
                    sharerequest = sharerindex is null ? 0 : sharerindex.SharesRequirements
                },
Example #2
0
        public ActionResult GeneratePage(Pageinexinfo pageindex, HttpPostedFileBase file)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                using (WechatEntities dc = new WechatEntities())
                {
                    string FriendsImages = "";
                    string adimages = "", friendimages = "";

                    pageindex.AuthorID  = 100;
                    pageindex.InputDate = System.DateTime.Now;


                    // pageindex.Id :  Pageindex.shareinfoID 是否存在
                    var PageinfoDB = dc.Pageinexinfoes.Where(a => a.shareinfoID == pageindex.Id).FirstOrDefault();
                    if (PageinfoDB != null)
                    {
                        //edit
                        var v = dc.Pageinexinfoes.Where(a => a.Id == PageinfoDB.Id).FirstOrDefault();
                        if (v != null)
                        {
                            if (Request.Files[0].FileName != "")
                            {
                                FriendsImages = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Request.Files[0].FileName);
                                savefile(Request.Files[0], FriendsImages);
                                v.FriendsImages = "images/upload/" + FriendsImages;
                            }
                            else
                            {
                                v.FriendsImages = PageinfoDB.FriendsImages;
                            }


                            v.Description        = pageindex.Description;
                            v.SharesRequirements = pageindex.SharesRequirements;


                            if (Request.Files[1].FileName != "")
                            {
                                adimages = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Request.Files[1].FileName);
                                savefile(Request.Files[1], adimages);
                                v.AdImages = "images/upload/" + adimages;
                            }
                            else
                            {
                                v.AdImages = PageinfoDB.AdImages;
                            }


                            if (Request.Files[2].FileName != "")
                            {
                                friendimages = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Request.Files[2].FileName);
                                savefile(Request.Files[2], friendimages);
                                v.friendimages = "images/upload/" + friendimages;
                            }
                            else
                            {
                                v.friendimages = PageinfoDB.friendimages;
                            }

                            v.AdURL = pageindex.AdURL; // test


                            string generateFile = System.IO.File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "/template/" + "index.tl", Encoding.GetEncoding("gb2312"));
                            generateFile = generateFile.Replace("{0}", string.Format("<img src='http://www.bbpdt.cn/{0}'  style='height:620px' />", v.FriendsImages));
                            generateFile = generateFile.Replace("{1}", pageindex.Description);
                            generateFile = generateFile.Replace("{2}", pageindex.AdURL);
                            generateFile = generateFile.Replace("{3}", string.Format("<img src='http://www.bbpdt.cn/{0}'   style='width:100%;'  />", v.AdImages));
                            Log(generateFile, "index" + pageindex.Id.ToString() + ".html");
                        }
                    }
                    else
                    {
                        //Save

                        if (Request.Files[0].FileName != "")
                        {
                            FriendsImages = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Request.Files[0].FileName);
                            savefile(Request.Files[0], FriendsImages);
                            pageindex.FriendsImages = "images/upload/" + FriendsImages;
                        }
                        if (Request.Files[1].FileName != "")
                        {
                            adimages = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Request.Files[1].FileName);
                            savefile(Request.Files[1], adimages);
                            pageindex.AdImages = "images/upload/" + adimages;
                        }
                        if (Request.Files[2].FileName != "")
                        {
                            friendimages = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Request.Files[2].FileName);
                            savefile(Request.Files[2], friendimages);
                            pageindex.friendimages = "images/upload/" + friendimages;
                        }
                        pageindex.shareinfoID = pageindex.Id;

                        // Save
                        dc.Pageinexinfoes.Add(pageindex);

                        string generateFile = System.IO.File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "/template/" + "index.tl", Encoding.GetEncoding("gb2312"));
                        generateFile = generateFile.Replace("{0}", string.Format("<img src='http://www.bbpdt.cn/{0}'  style='height:620px' />", pageindex.FriendsImages));
                        generateFile = generateFile.Replace("{1}", pageindex.Description);
                        generateFile = generateFile.Replace("{2}", pageindex.AdURL);
                        generateFile = generateFile.Replace("{3}", string.Format("<img src='http://www.bbpdt.cn/{0}'   style='width:100%;'  />", pageindex.AdImages));

                        Log(generateFile, "index" + pageindex.Id.ToString() + ".html");
                    }



                    dc.SaveChanges();
                    status = true;
                }
            }
            //return new JsonResult { Data = new { status = status} };
            return(RedirectToAction("Index"));
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";

            Pageinexinfo sharerindex = new Pageinexinfo();
            ShareLog     mylog       = new ShareLog();

            int    sharecounts, shareinfoid;
            string UserID, ShareUrl;

            try
            {
                UserID              = context.Request.Form["UserID"];   //context.Request.QueryString["UserID"]; //
                ShareUrl            = context.Request.Form["ShareUrl"]; //context.Request.QueryString["ShareUrl"];//
                shareinfoid         = int.Parse(weitang.StringExtensions.GetNumber(ShareUrl.Substring(ShareUrl.LastIndexOf('/') + 1)).ToString());
                mylog.userID        = UserID;
                mylog.shareUrl      = ShareUrl;
                mylog.shareinfoID   = shareinfoid;
                mylog.BrowseType    = DN.Framework.Utility.ClientHelper.GetUserAgent();
                mylog.ClientIp      = DN.Framework.Utility.ClientHelper.ClientIP();
                mylog.IsMobile      = DN.Framework.Utility.ClientHelper.GetIsMobileDevice() ? 1 : 0;
                mylog.OsName        = DN.Framework.Utility.ClientHelper.GetOsName();
                mylog.BrowseName    = DN.Framework.Utility.ClientHelper.GetBrowseName();
                mylog.BrowseVersion = DN.Framework.Utility.ClientHelper.GetBrowseVersion();

                var ipinfo = DN.WeiAd.Business.Services.IpTaoBaoHelper.GetIpResult(mylog.ClientIp);
                if (ipinfo != null)
                {
                    if (ipinfo.code == 0 && ipinfo.data != null)
                    {
                        mylog.Country = ipinfo.data.country;
                        mylog.Area    = ipinfo.data.area;
                        mylog.City    = ipinfo.data.city;
                        mylog.Region  = ipinfo.data.region;
                        mylog.County  = ipinfo.data.county;
                        mylog.Isp     = ipinfo.data.isp;
                    }
                }

                mylog.InputDate = System.DateTime.Now;
            }
            catch (Exception ex)
            {
                DN.Framework.Utility.LogHelper.Write(ex.Message.ToString());
                throw;
            }


            try
            {
                string cmd = string.Format(@" insert into ShareLog(userID, shareUrl, shareinfoID, BrowseType, ClientIp, IsMobile, OsName, BrowseName, BrowseVersion, Country,
                                                                        Area, City, Region, County, Isp,InputDate ) 
                                               values (N'{0}',N'{1}',N'{2}',N'{3}',N'{4}',{5},N'{6}',N'{7}',N'{8}',N'{9}',N'{10}',N'{11}',N'{12}',N'{13}',N'{14}',N'{15}')
                                              ",
                                           mylog.userID, mylog.shareUrl, mylog.shareinfoID, mylog.BrowseType, mylog.ClientIp, mylog.IsMobile, mylog.OsName, mylog.BrowseName,
                                           mylog.BrowseVersion, mylog.Country, mylog.Area, mylog.City, mylog.Region, mylog.County, mylog.Isp, mylog.InputDate
                                           );

                if (SQLServerHelper.ExcuteSql(cmd) > 0)
                {
                }
            }
            catch (Exception ex)
            {
                DN.Framework.Utility.LogHelper.Write(ex.Message);
            }

            WechatEntities wechat = new WechatEntities();

            sharecounts = wechat.ShareLogs.Where(a => a.userID == UserID && a.shareUrl == ShareUrl).ToList().Count;
            sharerindex = wechat.Pageinexinfo.Where(a => a.shareinfoID == shareinfoid).FirstOrDefault();

            //
            string result = JsonConvert.SerializeObject(new ApiResponse
            {
                r = "1",
                d = new
                {
                    sharenums    = sharecounts,
                    sharerequest = sharerindex is null ? 0 : sharerindex.SharesRequirements,
                    shareimages  = sharerindex is null ? "" : sharerindex.friendimages
                },