Esempio n. 1
0
 public static Uri ForumPostUrl(int forumPostID, ForumSubCategory feedItem, int pageCount)
 {
     return (forumPostID == 0)
         ? feedItem.SubForumURL
         : new Uri(string.Format(LinkFormat,
             feedItem.SubForumURL,
             ((pageCount > 1)
                 ? "/" + pageCount.ToString(CultureInfo.InvariantCulture)
                 : string.Empty),
             forumPostID.ToString(CultureInfo.InvariantCulture)));
 }
Esempio n. 2
0
        public ActionResult EditSubCategory(ForumSubCategory model)
        {
            using (var context = new DasKlubDbContext())
            {
                ForumSubCategory currentThread = context.ForumSubCategory.First(
                    currentForumSubCategory =>
                        currentForumSubCategory.ForumSubCategoryID == model.ForumSubCategoryID);

                if (_ua.UserAccountID != currentThread.CreatedByUserID && !_ua.IsAdmin)
                {
                    throw new UnauthorizedAccessException();
                }

                currentThread.UpdatedByUserID = _ua.UserAccountID;

                if (currentThread.ForumCategoryID != model.ForumCategoryID)
                {
                    // update switched category
                    var originalForum = context.ForumCategory.First(x => x.ForumCategoryID == currentThread.ForumCategoryID);
                    var newForum = context.ForumCategory.First(x => x.ForumCategoryID == model.ForumCategoryID);

                    originalForum.PostCount -= currentThread.PostCount;
                    originalForum.ThreadCount -= 1;

                    newForum.PostCount += currentThread.PostCount;
                    newForum.ThreadCount += 1;

                    var newForumLastThread = context.ForumSubCategory.First(x => x.ForumSubCategoryID == newForum.LastActiveSubCategoryId);

                    if (newForumLastThread.LastActiveDateTimeUtc < currentThread.LastActiveDateTimeUtc)
                    {
                        newForumLastThread.LastActiveDateTimeUtc = currentThread.LastActiveDateTimeUtc;
                        newForumLastThread.LastActiveForumPostId = currentThread.LastActiveForumPostId;
                        newForumLastThread.LastActiveUserId = currentThread.LastActiveUserId;
                    }

                    var originalForumLastThread = context.ForumSubCategory
                        .OrderByDescending(x => x.LastActiveDateTimeUtc)
                        .First(x => x.ForumSubCategoryID != currentThread.ForumSubCategoryID);

                    if (originalForumLastThread.LastActiveDateTimeUtc < currentThread.LastActiveDateTimeUtc)
                    {
                        currentThread.LastActiveDateTimeUtc = originalForumLastThread.LastActiveDateTimeUtc;
                        currentThread.LastActiveForumPostId = originalForumLastThread.LastActiveForumPostId;
                        currentThread.LastActiveUserId = originalForumLastThread.LastActiveUserId;
                    }

                    currentThread.ForumCategoryID = model.ForumCategoryID;
                }

                currentThread.Title = model.Title;
                currentThread.Description = model.Description;

                context.Entry(currentThread).State = EntityState.Modified;
                context.SaveChanges();

                model.Key = currentThread.Key;
                model.ForumCategory =
                    context.ForumCategory.First(forum => forum.ForumCategoryID == currentThread.ForumCategoryID);
            }

            return new RedirectResult(model.SubForumURL.ToString());
        }
Esempio n. 3
0
        public ActionResult CreateSubCategory(ForumSubCategory model)
        {
            if (_mu == null) return new EmptyResult();

            using (var context = new DasKlubDbContext())
            {
                if (model == null) return new EmptyResult();

                ForumCategory forum = context.ForumCategory.First(x => x.Key == model.Key);

                ViewBag.Forum = forum;

                if (!ModelState.IsValid)
                {
                    return View(model);
                }

                if (forum.ThreadsRequirePermission && ((_ua == null) || !_ua.IsAdmin))
                {
                    return new EmptyResult();
                }

                model.LastActiveDateTimeUtc = DateTime.UtcNow; // nulls are allowed, change when modifying
                model.LastActiveUserId = _ua.UserAccountID;
                model.ForumCategoryID = forum.ForumCategoryID;
                model.CreatedByUserID = _ua.UserAccountID;
                model.Key = FromString.UrlKey(model.Title);
                model.Title = model.Title.Trim();
                model.Description = model.Description.Trim();
                model.PostCount += 1;

                var existingThreadInForum = context.ForumSubCategory.FirstOrDefault(
                    forumSubCategory =>
                        forumSubCategory.ForumCategoryID == model.ForumCategoryID &&
                        forumSubCategory.Key             == model.Key);

                if (existingThreadInForum != null)
                {
                    // TODO: LOCALIZE
                    existingThreadInForum.ForumCategory = forum;

                    ModelState.AddModelError("Title",
                        string.Format(@"The title '{0}' is already taken, change your title.",
                        model.Title));

                    return View(model);
                }

                context.ForumSubCategory.Add(model);

                //update the forum category
                forum.PostCount += 1;
                forum.ThreadCount += 1;

                context.Entry(forum).State = EntityState.Modified;

                var notification = new ForumPostNotification
                {
                    CreatedByUserID = Convert.ToInt32(_mu.ProviderUserKey),
                    IsRead = true,
                    UserAccountID = Convert.ToInt32(_mu.ProviderUserKey),
                    ForumSubCategoryID = model.ForumSubCategoryID
                };

                context.ForumPostNotification.Add(notification);

                context.SaveChanges();

                // update to the last active
                forum.LastActiveSubCategoryId = model.ForumSubCategoryID;
                context.Entry(forum).State = EntityState.Modified;
                model.LastActiveDateTimeUtc = model.CreateDate;
                context.Entry(model);

                context.SaveChanges();

                return RedirectToAction("ForumPost", "Forum", new {subkey = model.Key, key = forum.Key});
            }
        }