示例#1
0
文件: Social.cs 项目: fizikci/Cinar
        private void post()
        {
            if (Provider.User.IsAnonim())
                return;

            int lat = 0;
            int.TryParse(context.Request["lat"], out lat);
            int lng = 0;
            int.TryParse(context.Request["lng"], out lng);
            string metin = context.Request["metin"];
            if (string.IsNullOrWhiteSpace(metin) && (Provider.Request.Files["Picture"] == null || Provider.Request.Files["Picture"].ContentLength == 0))
                throw new Exception("Post empty");
            int replyToPostId = 0;
            int.TryParse(context.Request["replyToPostId"], out replyToPostId);

            Post replyToPost = null;
            if(replyToPostId>0) replyToPost = Provider.Database.Read<Post>(replyToPostId);

            context.Response.ContentType = "text/html";

            try
            {
                Post p = new Post
                {
                    LangId = Provider.CurrentLanguage.Id,
                    Lat = lat,
                    Lng = lng,
                    Metin = metin==null ? "" : metin,
                    ReplyToPostId = replyToPostId>0 ? (replyToPost.OriginalPost == null ? replyToPostId : replyToPost.OriginalPost.Id) : 0
                };

                p.Save();

                ViewPost vp = new ViewPost()
                    {
                        SharerNick = "",
                        UserAvatar = Provider.GetThumbPath(p.InsertUser.Avatar, 48, 48, false),
                        UserFullName = p.InsertUser.FullName,
                        UserNick = p.InsertUser.Nick
                    };
                p.CopyPropertiesWithSameName(vp);

                context.Response.Write("<html><head></head><body><script>window.parent.paylas(" + vp.ToJSON() + ");</script></body></html>");
            }
            catch(Exception ex)
            {
                context.Response.Write("<html><head></head><body><script>window.parent.niceAlert(" + ex.Message.ToJS() + ");</script></body></html>");
            }
        }
示例#2
0
 public static ViewPost GetRandomPostAd()
 {
     if (HttpContext.Current.Cache["post_ads"] == null)
     {
         List<PostAd> ads = Provider.Database.ReadList<PostAd>("select * from PostAd where AdStatus=1");
         HttpContext.Current.Cache.Add("post_ads", ads, null, DateTime.Now.AddSeconds(10), Cache.NoSlidingExpiration, CacheItemPriority.High,
             (String name, Object val, CacheItemRemovedReason r)=>{
                 foreach (var ad in (List<PostAd>)val)
                     ad.Save();
             }
         );
     }
     List<PostAd> cachedAds = (List<PostAd>) HttpContext.Current.Cache["post_ads"];
     if (cachedAds.Count > 0)
     {
         PostAd p = cachedAds[new Random().Next(cachedAds.Count)];
         p.ViewCount++;
         ViewPost vp = new ViewPost()
         {
             SharerNick = "",
             UserAvatar = Provider.GetThumbPath(p.InsertUser.Avatar, 48, 48, false),
             UserFullName = p.InsertUser.FullName,
             UserNick = p.InsertUser.Nick
         };
         Provider.Database.Read<Post>(p.PostId).CopyPropertiesWithSameName(vp);
         return vp;
     }
     else
         return null;
 }