Beispiel #1
0
 public static Uri ForumPostUri(ForumFeedModel topFeedItem, int pageCount, ForumPost mostRecentPostToTopThread)
 {
     return new Uri(string.Format(LinkFormat,
         topFeedItem.ForumSubCategory.SubForumURL,
         ((pageCount > 1)
             ? "/" + pageCount.ToString(CultureInfo.InvariantCulture)
             : string.Empty),
         mostRecentPostToTopThread.ForumPostID.ToString(CultureInfo.InvariantCulture)));
 }
Beispiel #2
0
 public static Uri ForumPostUrl(ForumPost lastPost, ForumFeedModel feedItem, int pageCount)
 {
     return (lastPost == null)
         ? feedItem.ForumSubCategory.SubForumURL
         : new Uri(string.Format(LinkFormat,
             feedItem.ForumSubCategory.SubForumURL,
             ((pageCount > 1)
                 ? "/" + pageCount.ToString(CultureInfo.InvariantCulture)
                 : string.Empty),
             lastPost.ForumPostID.ToString(CultureInfo.InvariantCulture)));
 }
Beispiel #3
0
        public ActionResult EditForumPost(ForumPost model)
        {
            using (var context = new DasKlubDbContext())
            {
                ForumPost forumPost = context.ForumPost.First(
                    currentForumPost => currentForumPost.ForumPostID == model.ForumPostID);

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

                forumPost.Detail = model.Detail;

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

                ForumSubCategory subForum = context.ForumSubCategory.First(
                    currentForumSubCategory =>
                        currentForumSubCategory.ForumSubCategoryID == model.ForumSubCategoryID);

                subForum.ForumCategory =
                    context.ForumCategory.First(forum => forum.ForumCategoryID == subForum.ForumCategoryID);

                return new RedirectResult(subForum.SubForumURL.ToString());
            }
        }
Beispiel #4
0
        public ActionResult CreateForumPost(ForumPost model, int forumSubCategoryID)
        {
            using (var context = new DasKlubDbContext())
            {
                string currentLang = Utilities.GetCurrentLanguageCode();

                ForumSubCategory subForum = context.ForumSubCategory
                    .First(x => x.ForumSubCategoryID == forumSubCategoryID);

                if (!ModelState.IsValid)
                {
                    ViewBag.SubForum = subForum;

                    return View(model);
                }

                var ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey));

                model.ForumSubCategoryID = forumSubCategoryID;
                model.CreatedByUserID = ua.UserAccountID;
                context.ForumPost.Add(model);

                ForumPostNotification currentUserNotification = context.ForumPostNotification
                    .FirstOrDefault(
                        x => x.ForumSubCategoryID == forumSubCategoryID && x.UserAccountID == ua.UserAccountID);

                if (currentUserNotification == null || currentUserNotification.ForumPostNotificationID == 0)
                {
                    var notification = new ForumPostNotification
                    {
                        CreatedByUserID = Convert.ToInt32(_mu.ProviderUserKey),
                        IsRead = true,
                        UserAccountID = Convert.ToInt32(_mu.ProviderUserKey),
                        ForumSubCategoryID = forumSubCategoryID
                    };

                    context.ForumPostNotification.Add(notification);
                }

                List<ForumPostNotification> allUserNotifications =
                    context.ForumPostNotification.Where(x => x.ForumSubCategoryID == forumSubCategoryID).ToList();

                subForum.ForumCategory = context.ForumCategory.First(x => x.ForumCategoryID == subForum.ForumCategoryID);

                if (context.ForumPost.FirstOrDefault(
                    x =>
                        x.ForumSubCategoryID == forumSubCategoryID && x.Detail == model.Detail &&
                        x.CreatedByUserID == ua.UserAccountID) != null) return new EmptyResult();

                Thread.CurrentThread.CurrentUICulture =
                    CultureInfo.CreateSpecificCulture(SiteEnums.SiteLanguages.EN.ToString());

                Thread.CurrentThread.CurrentCulture =
                    CultureInfo.CreateSpecificCulture(SiteEnums.SiteLanguages.EN.ToString());

                foreach (var forumPostNotification in
                        allUserNotifications.Where(
                            forumPostNotification => forumPostNotification.UserAccountID != ua.UserAccountID))
                {
                    forumPostNotification.IsRead = false;
                    forumPostNotification.UpdatedByUserID = Convert.ToInt32(_mu.ProviderUserKey);
                    context.Entry(forumPostNotification).State = EntityState.Modified;

                    var notifiedUser = new UserAccount(forumPostNotification.UserAccountID);
                    var notifiedUserDetails = new UserAccountDetail();
                    notifiedUserDetails.GetUserAccountDeailForUser(forumPostNotification.UserAccountID);

                    if (!notifiedUserDetails.EmailMessages) continue;

                    string title = ua.UserName + " => " + subForum.Title;
                    var body = new StringBuilder(100);
                    body.Append(Messages.New);
                    body.Append(": ");
                    body.Append(subForum.SubForumURL);
                    body.AppendLine();
                    body.AppendLine();
                    body.Append(model.Detail);
                    body.AppendLine();
                    body.AppendLine();
                    body.Append(Messages.Reply);
                    body.Append(": ");
                    body.AppendFormat("{0}/create", subForum.SubForumURL);

                    try
                    {
                        _mail.SendMail(AmazonCloudConfigs.SendFromEmail, notifiedUser.EMail, title, body.ToString());
                    }
                    catch (Exception ex)
                    {
                        Utilities.LogError(ex);
                    }
                }

                var forum = context.ForumCategory.First(x => x.ForumCategoryID == subForum.ForumCategoryID);

                forum.PostCount += 1;
                forum.LastActiveSubCategoryId = forumSubCategoryID;
                context.Entry(forum).State = EntityState.Modified;

                try
                {
                    context.SaveChanges();

                    subForum.PostCount += 1;
                    subForum.LastActiveDateTimeUtc = model.CreateDate;
                    subForum.LastActiveForumPostId = model.ForumPostID;
                    subForum.LastActiveUserId = model.CreatedByUserID;
                    context.Entry(subForum).State = EntityState.Modified;

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Utilities.LogError(ex);
                }

                Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(currentLang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(currentLang);

                Response.Redirect(subForum.SubForumURL.ToString());

                return new EmptyResult();
            }
        }