Example #1
0
 public ActionResult InsertUpdateForumItem(ForumModel fo)
 {
     if (fo.EditedForumItem.Id > 0)
         Locator.GetDbForumManager().UpdateForumItem(fo.EditedForumItem.Id, fo.EditedForumItem.Message, fo.EditedForumItem.CreatorId);
     else
     {
         var forumItemId = Locator.GetDbForumManager().CreateForumItem(fo.EventModel.Id, fo.EditedForumItem.Message, fo.EditedForumItem.CreatorId);
         Locator.GetDbForumManager().SetLastVisitedForumItemId(fo.EditedForumItem.CreatorId, fo.EventModel.Id, forumItemId);
     }
     return RedirectToAction("ShowForum", "Forum", new { fo.EventModel.Id });
 }
Example #2
0
        public ActionResult ShowEditForum(int id, int forumItemId)
        {
            // Validation section ============================================================================================
            var dbEvent = Locator.GetDbEventManager().GetEventById(id);
            if (dbEvent == null)
                throw new HttpException(404, "Událost nenalezena");

            var eventModel = ModelConvertor.ConvertToEventModelNew(dbEvent);

            if (!eventModel.HasRightToAccess())
                throw new Exception("Uživatel nemá přístup k této události a proto ani k jejímu seznamu příspěvků");

            var forumItemsDto   = Locator.GetDbForumManager().GetForumList(id, GetDatabasePagerControl(id));
            var forumItemModels = forumItemsDto.ForumItemList.Select(ModelConvertor.ConvertToForumItemModel).ToList();
            var loggedUserId    = RightManager.Instance.LoggedUserSession.Id;

            PagingSession.SetPaging(forumItemsDto.TotalRecords);

            // when nobody is logged in (public person) we set int.max so this person will never have any unread forum item
            var lastVisitedForumItemId = loggedUserId > 0 ? Locator.GetDbForumManager().GetLastVisitedForumItemId(loggedUserId, id) : int.MaxValue;

            // now we need to set which forum items are already visited and which not
            forumItemModels.Where(fim => fim.Id <= lastVisitedForumItemId).ToList().ForEach(fim => fim.IsAlreadyVisited = true);

            var model = new ForumModel()
            {
                EventModel      = ModelConvertor.ConvertToEventModelNew(dbEvent),
                ForumItems      = forumItemModels.ToList(),
                Paging          = PagingSession,
                EditedForumItem = GetForumItem(forumItemId, dbEvent.Id)
            };

            // finally we need to set, only when we have logged person and we have at least one forum item
            if (forumItemModels.Any() && loggedUserId > 0)
                Locator.GetDbForumManager().SetLastVisitedForumItemId(loggedUserId, dbEvent.Id);

            return View(model);
        }