Esempio n. 1
0
        public ActionResult NewPost(int?categoryID, int?threadID, int?forumPostID)
        {
            var res = new NewPostResult();
            var db  = new ZkDataContext();

            var penalty = ZkData.Punishment.GetActivePunishment(Global.AccountID, "", 0, x => x.BanForum);

            if (penalty != null)
            {
                return(Content(string.Format("You cannot post while banned from forum!\nExpires: {0} UTC\nReason: {1}", penalty.BanExpires, penalty.Reason)));
            }

            var clan = db.Clans.FirstOrDefault(x => x.ForumThreadID == threadID);

            if (clan != null && Global.ClanID != clan.ClanID)
            {
                return(Content(string.Format("You are not a member of {0}, you cannot post in their clan thread", clan.ClanName)));
            }

            if (threadID.HasValue)
            {
                var t = db.ForumThreads.Single(x => x.ForumThreadID == threadID.Value);
                res.CurrentThread = t;
                res.LastPosts     = res.CurrentThread.ForumPosts.OrderByDescending(x => x.ForumPostID).Take(20);
                if (!categoryID.HasValue)
                {
                    categoryID = t.ForumCategoryID;
                }
            }

            res.Path = GetCategoryPath(categoryID, db);
            var category = res.Path.LastOrDefault();

            res.CurrentCategory = category;
            if (forumPostID != null)
            {
                ForumPost post = db.ForumPosts.Single(x => x.ForumPostID == forumPostID);
                if (!Global.IsZeroKAdmin && Global.AccountID != post.AuthorAccountID)
                {
                    return(Content("You cannot edit this post"));
                }
                res.EditedPost = post;
            }
            if (threadID != null)
            {
                var thread = res.CurrentThread;
                res.CanSetTopic = (thread.ForumPosts.Count > 0 && thread.ForumPosts[0].ForumPostID == forumPostID &&
                                   !category.IsClans && !category.IsMaps && !category.IsMissions && !category.IsPlanets && !category.IsSpringBattles);
            }
            else
            {
                res.CanSetTopic = true;
            }

            return(View(res));
        }
        public ActionResult NewPost(int?categoryID, int?threadID, int?forumPostID, string wikiKey)
        {
            var res = new NewPostResult();
            var db  = new ZkDataContext();

            var penalty = Punishment.GetActivePunishment(Global.AccountID, Request.UserHostAddress, 0, null, x => x.BanForum);

            if (penalty != null)
            {
                return
                    (Content(
                         string.Format("You cannot post while banned from forum!\nExpires: {0} UTC\nReason: {1}", penalty.BanExpires, penalty.Reason)));
            }

            if (threadID.HasValue && threadID > 0)
            {
                var clan = db.Clans.FirstOrDefault(x => x.ForumThreadID == threadID);
                if (clan != null && Global.ClanID != clan.ClanID)
                {
                    return(Content(string.Format("You are not a member of {0}, you cannot post in their clan thread", clan.ClanName)));
                }

                var t = db.ForumThreads.Single(x => x.ForumThreadID == threadID.Value);
                res.CurrentThread = t;
                res.LastPosts     = res.CurrentThread.ForumPosts.OrderByDescending(x => x.ForumPostID).Take(20);
                if (!categoryID.HasValue)
                {
                    categoryID = t.ForumCategoryID;
                }
            }
            if (!categoryID.HasValue)
            {
                categoryID =
                    db.ForumCategories.Where(x => !x.IsLocked && x.ForumMode == ForumMode.General).OrderBy(x => x.SortOrder).First().ForumCategoryID;
                // post in general by default
            }

            var category = db.ForumCategories.FirstOrDefault(x => x.ForumCategoryID == categoryID);

            res.Path = category?.GetPath() ?? new List <ForumCategory>();

            res.CurrentCategory = category;
            if (forumPostID != null)
            {
                var post = db.ForumPosts.Single(x => x.ForumPostID == forumPostID);
                if (!post.CanEdit(Global.Account))
                {
                    return(Content("You cannot edit this post"));
                }
                res.EditedPost = post;
            }
            if (threadID != null)
            {
                var thread = res.CurrentThread;
                res.CanSetTopic = (thread.ForumPosts.Count > 0 && thread.ForumPosts.First().ForumPostID == forumPostID &&
                                   (category.ForumMode == ForumMode.General || category.ForumMode == ForumMode.Wiki || category.ForumMode == ForumMode.Archive));
            }
            else
            {
                res.CanSetTopic = true;
            }

            res.WikiKey = wikiKey;

            return(View(res));
        }
        public ActionResult NewPost(int? categoryID, int? threadID, int? forumPostID, string wikiKey) {
            var res = new NewPostResult();
            var db = new ZkDataContext();

            var penalty = Punishment.GetActivePunishment(Global.AccountID, Request.ServerVariables["REMOTE_ADDR"], 0, x => x.BanForum);
            if (penalty != null)
            {
                return
                    Content(
                        string.Format("You cannot post while banned from forum!\nExpires: {0} UTC\nReason: {1}", penalty.BanExpires, penalty.Reason));
            }

            if (threadID.HasValue && threadID > 0)
            {
                var clan = db.Clans.FirstOrDefault(x => x.ForumThreadID == threadID);
                if (clan != null && Global.ClanID != clan.ClanID) return Content(string.Format("You are not a member of {0}, you cannot post in their clan thread", clan.ClanName));

                var t = db.ForumThreads.Single(x => x.ForumThreadID == threadID.Value);
                res.CurrentThread = t;
                res.LastPosts = res.CurrentThread.ForumPosts.OrderByDescending(x => x.ForumPostID).Take(20);
                if (!categoryID.HasValue) categoryID = t.ForumCategoryID;
            }
            if (!categoryID.HasValue)
            {
                categoryID =
                    db.ForumCategories.Where(x => !x.IsLocked && x.ForumMode == ForumMode.General).OrderBy(x => x.SortOrder).First().ForumCategoryID;
                    // post in general by default
            }

            var category = db.ForumCategories.FirstOrDefault(x => x.ForumCategoryID == categoryID);
            res.Path = category?.GetPath() ?? new List<ForumCategory>();
            
            res.CurrentCategory = category;
            if (forumPostID != null)
            {
                var post = db.ForumPosts.Single(x => x.ForumPostID == forumPostID);
                if (!post.CanEdit(Global.Account)) return Content("You cannot edit this post");
                res.EditedPost = post;
            }
            if (threadID != null)
            {
                var thread = res.CurrentThread;
                res.CanSetTopic = (thread.ForumPosts.Count > 0 && thread.ForumPosts.First().ForumPostID == forumPostID &&
                                   (category.ForumMode == ForumMode.General || category.ForumMode == ForumMode.Wiki || category.ForumMode == ForumMode.Archive));
            } else res.CanSetTopic = true;

            res.WikiKey = wikiKey;

            return View(res);
        }
		public ActionResult NewPost(int? categoryID, int? threadID, int? forumPostID)
		{
			var res = new NewPostResult();
			var db = new ZkDataContext();

            var penalty = ZkData.Punishment.GetActivePunishment(Global.AccountID, "", 0, x => x.BanForum);
            if (penalty != null)
            {
                return Content(string.Format("You cannot post while banned from forum!\nExpires: {0} UTC\nReason: {1}", penalty.BanExpires, penalty.Reason));
            }

			if (threadID.HasValue && threadID > 0)
			{
                var clan = db.Clans.FirstOrDefault(x => x.ForumThreadID == threadID);
                if (clan != null && Global.ClanID != clan.ClanID)
                {
                    return Content(string.Format("You are not a member of {0}, you cannot post in their clan thread", clan.ClanName));
                }

				var t = db.ForumThreads.Single(x => x.ForumThreadID == threadID.Value);
				res.CurrentThread = t;
				res.LastPosts = res.CurrentThread.ForumPosts.OrderByDescending(x => x.ForumPostID).Take(20);
				if (!categoryID.HasValue) categoryID = t.ForumCategoryID;
			}

			res.Path = GetCategoryPath(categoryID, db);
            var category = res.Path.LastOrDefault();
			res.CurrentCategory = category;
            if (forumPostID != null) {
                ForumPost post = db.ForumPosts.Single(x=>x.ForumPostID == forumPostID);
                if (!Global.IsZeroKAdmin && Global.AccountID != post.AuthorAccountID)
                {
                    return Content("You cannot edit this post");
                }
                res.EditedPost= post;   
            }
            if (threadID != null)
            {
                var thread = res.CurrentThread;
                res.CanSetTopic = (thread.ForumPosts.Count > 0 && thread.ForumPosts.First().ForumPostID == forumPostID 
                    && !category.IsClans && !category.IsMaps && !category.IsMissions && !category.IsPlanets && !category.IsSpringBattles);
            }
            else res.CanSetTopic = true;

			return View(res);
		}