Esempio n. 1
0
        // GET: Posts
        public async Task <IActionResult> Index(string postTopic, string searchString)
        {
            // Use LINQ to get list of genres.
            IQueryable <string> topicQuery = from p in _context.Post
                                             orderby p.Topic
                                             select p.Topic;

            var movies = from p in _context.Post
                         select p;

            if (!string.IsNullOrEmpty(searchString))
            {
                movies = movies.Where(s => s.Title.Contains(searchString));
            }

            if (!string.IsNullOrEmpty(postTopic))
            {
                movies = movies.Where(x => x.Topic == postTopic);
            }

            var postTopicVM = new PostTopicViewModel
            {
                Topics = new SelectList(await topicQuery.Distinct().ToListAsync()),
                Posts  = await movies.ToListAsync()
            };

            return(View(postTopicVM));
        }
Esempio n. 2
0
 // GET: Forum
 public ActionResult AddPost()
 {
     GetTopicsForCurrentPost();
     using (WorkFlowDbContext db = new WorkFlowDbContext())
     {
         var ListData = db.Topics.ToList();
         var dispaly  = new PostTopicViewModel
         {
             displayTopic = ListData
         };
         return(View(dispaly));
     }
 }
Esempio n. 3
0
        private async Task StoreToAzureTable(PostTopicViewModel source, Topic target)
        {
            List <StoreContentViewModel> contentList = new List <StoreContentViewModel>();

            foreach (var item in source.Contents)
            {
                ImageViewModel model = new ImageViewModel();
                if (item.Image != null)
                {
                    if (Request.Form.Files != null && Request.Form.Files.Count > 0)
                    {
                        foreach (IFormFile formFile in Request.Form.Files)
                        {
                            if (formFile.Name.Equals(item.Image.Name))
                            {
                                model.Key      = item.Image.Key;
                                model.Name     = item.Image.Name;
                                model.ImageUrl = await SavePhoto(formFile);
                            }
                        }
                    }
                }
                contentList.Add(new StoreContentViewModel
                {
                    HtmlContent = item.HtmlContent,
                    Code        = item.Code,
                    Image       = model
                });
            }

            var settings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };
            //convert to content to json
            var content = JsonConvert.SerializeObject(contentList, Formatting.None, settings);
            //Store html content data  on the table storage
            await StorageHelper.InsertOrMerge(target.RowId.ToString(), target.TopicId.ToString(), content);
        }
        public async Task <IActionResult> getTopicById([FromRoute] int topicId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var topic = await _topicRepository.Find(topicId);

            if (topic == null)
            {
                return(NotFound());
            }

            var blogEntity = await StorageHelper.GetTableEntity(topic.RowId.ToString(), topic.TopicId.ToString());

            var settings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };


            var topicVM = new PostTopicViewModel
            {
                TopicId    = topic.TopicId,
                Title      = topic.Title,
                Contents   = JsonConvert.DeserializeObject <List <StoreContentViewModel> >(blogEntity.Content, settings),
                IsActive   = topic.IsActive,
                LessonId   = topic.LessonId,
                CourseId   = topic.Lesson.CourseId,
                CategoryId = _courseRepository.Find(topic.Lesson.CourseId).Result.CategoryId
            };

            return(Ok(topicVM));
        }
Esempio n. 5
0
        public async Task <IActionResult> post(PostTopicViewModel model)
        {
            if (ModelState.IsValid)
            {
                // new topic posted
                if (model.ReplyID == 0)
                {
                    // check title
                    if (model.Title.Length < 10)
                    {
                        model.Message = SiteConfig.forumLocalizer["_forum_post_msg_09"].Value;
                        return(View(model));
                    }

                    if (UtilityBLL.isLongWordExist(model.Title) || UtilityBLL.isLongWordExist(model.Title))
                    {
                        model.Message = SiteConfig.generalLocalizer["_invalid_title"];
                        return(View(model));
                    }
                }

                // Add information in table
                var topics = new JGN_ForumTopics();
                if (model.TopicID > 0)
                {
                    topics.id = model.TopicID;
                }

                topics.forumid = model.ForumID;

                string content = UGeneral.SanitizeText(model.Description);

                // Process Contents -> links, bbcodes etc
                // content = UtilityBLL.Process_Content_Text(content);
                // Generate Album Preview
                //content = AlbumsBLL.Generate_Blog_Gallery_Previews(content);

                topics.description = content;

                if (model.ReplyID > 0)
                {
                    var _lst = await ForumTopicBLL.LoadItems(_context, new ForumTopicEntity()
                    {
                        id      = model.TopicID,
                        loadall = true
                    });

                    if (_lst.Count > 0)
                    {
                        topics.tags    = _lst[0].tags;
                        topics.title   = _lst[0].title;
                        topics.forumid = _lst[0].forumid;
                        if (topics.title.Length > 200)
                        {
                            topics.title = topics.title.Substring(0, 199);
                        }
                    }
                }
                else
                {
                    if (model.Tags != null)
                    {
                        topics.tags = model.Tags;
                        if (topics.tags.Length > 300)
                        {
                            topics.tags = topics.tags.Substring(0, 299);
                        }
                    }

                    topics.title = model.Title;
                }
                topics.userid = model.UserName;

                int isapproved = 1;
                if (Jugnoon.Settings.Configs.GeneralSettings.content_approval == 0 && !model.isAdmin && model.ReplyID == 0)
                {
                    isapproved = 0; // manual approval
                }
                topics.isapproved = (byte)isapproved;
                topics.isenabled  = 1;
                topics.replyid    = model.ReplyID;

                topics = await ForumTopicBLL.Process(_context, topics, model.isAdmin);

                if (model.Tags != "")
                {
                    // Process tags
                    TagsBLL.Process_Tags(_context, model.Tags, TagsBLL.Types.Forums, 0);
                }


                // Mail Procesing Section
                if (model.TopicID == 0 && model.ReplyID == 0)
                {
                    ProcessMail(topics.id, topics.replyid, topics.userid, model.GroupID, model.Description, model.Title);
                    // add newly added topic id in struct for user activity and group posting
                    //topics.topicid = topics.topicid;
                }

                if (model.ReplyID > 0)
                {
                    // topic is posted in reply
                    // redirect to topic
                    return(Redirect(Forum_Urls.Prepare_Topic_Url(topics.replyid, topics.title, model.isAdmin) + "?status=posted"));
                }

                return(Redirect(Forum_Urls.Prepare_Topic_Url(topics.id, topics.title, model.isAdmin) + "?status=posted"));
            }

            // initialize values
            if (model.ForumID == 0)
            {
                model.ForumList = await ForumBLLC.LoadItems(_context, new ForumEntity()
                {
                    loadall = true,

                    iscache = true
                });
            }
            model.Message = "Validation Error";
            return(View(model));
        }
Esempio n. 6
0
        public string Load_Topic_Info(PostTopicViewModel model)
        {
            var _lst = ForumTopicBLL.LoadItems(_context, new ForumTopicEntity()
            {
                id         = model.ReplyID,
                loadall    = true,
                singlepost = true
            }).Result;

            if (_lst.Count > 0)
            {
                // further validation
                if (_lst[0].replyid > 0)
                {
                    model.ReplyID = 0;
                    return(SiteConfig.forumLocalizer["_forum_post_msg_02"].Value);
                }
                if (_lst[0].type == 1)
                {
                    model.ReplyID = 0; // reset it to post new topic
                    return(SiteConfig.forumLocalizer["_forum_post_msg_03"].Value);
                }
                if (_lst[0].islocked == 1)
                {
                    model.ReplyID = 0; // reset it to post new topic
                    return(SiteConfig.forumLocalizer["_forum_post_msg_04"].Value);
                }
                if (_lst[0].isresolved == 1)
                {
                    model.ReplyID = 0; // reset it to post new topic
                    return(SiteConfig.forumLocalizer["_forum_post_msg_05"].Value);
                }
                if (_lst[0].isapproved == 0)
                {
                    model.ReplyID = 0; // reset it to post new topic
                    return(SiteConfig.forumLocalizer["_forum_post_msg_06"].Value);
                }
                if (_lst[0].isenabled == (byte)EnabledTypes.Disabled)
                {
                    model.ReplyID = 0; // reset it to post new topic
                    return(SiteConfig.forumLocalizer["_forum_post_msg_07"].Value);
                }
                // Validation completed
                model.showTitle       = false;
                model.showTags        = false;
                model.showForumOption = false;
                model.ForumID         = _lst[0].forumid;
                model.Title           = "Re: " + _lst[0].title;
                model.Tags            = _lst[0].tags;

                if (HttpContext.Request.Query["nq"].Count > 0)
                {
                    if (HttpContext.Request.Query["nq"].ToString() == "0")
                    {
                        // quote is on
                        if (HttpContext.Request.Query["p"].Count > 0)
                        {
                            long postid = Convert.ToInt64(HttpContext.Request.Query["p"]);
                            if (postid > 0)
                            {
                                string desc = ForumTopicBLL.Return_Value(_context, postid, "description");
                                desc = UtilityBLL.CompressCodeBreak(desc); // replace \n with <br />
                                desc = WebUtility.HtmlDecode(desc);
                                model.Description = "\n[quote]" + desc + "[/quote]\n";
                            }
                        }
                    }
                }
                return("OK");
            }
            else
            {
                model.ReplyID = 0;
                return(SiteConfig.forumLocalizer["_forum_post_msg_08"].Value);
            }
        }
Esempio n. 7
0
        // GET: forums/post
        public async Task <IActionResult> post(long?id)
        {
            var model = new PostTopicViewModel();

            model.AlertType  = AlertTypes.Error;
            model.PostAccess = true;

            long TopicID = 0;

            if (id != null)
            {
                TopicID = (long)id;
            }

            if (!User.Identity.IsAuthenticated)
            {
                string redirect_url = Config.GetUrl() + "forums/post";
                return(Redirect(Config.GetUrl() + "login?returnUrl=" + redirect_url));
            }

            model.isAdmin = false;


            model.UserName = SiteConfig.userManager.GetUserName(User);

            if (HttpContext.Request.Query["gd"].Count > 0)
            {
                model.GroupID = Convert.ToInt64(HttpContext.Request.Query["gd"]);
            }

            model.showTitle       = true;
            model.showTags        = true;
            model.showForumOption = true;

            if (HttpContext.Request.Query["f"].Count > 0)
            {
                model.ForumID         = Convert.ToInt32(HttpContext.Request.Query["f"]);
                model.showForumOption = false;
            }
            else
            {
                // load forums for manual selection
                model.ForumList = await ForumBLLC.LoadItems(_context, new ForumEntity()
                {
                    loadall = true,
                    iscache = true
                });
            }


            // use for posting reply
            if (HttpContext.Request.Query["t"].Count > 0)
            {
                model.ReplyID = Convert.ToInt32(HttpContext.Request.Query["t"]);

                var status = Load_Topic_Info(model);
                if (status != "OK")
                {
                    model.Message = status;
                    return(View(model));
                }
            }


            // use for updat posting only
            if (TopicID > 0)
            {
                model.TopicID         = TopicID;
                model.showForumOption = false;

                if (!model.isAdmin)
                {
                    // Security Validation -> Awnership Check
                    if (!ForumTopicBLL.Check(_context, model.TopicID, SiteConfig.userManager.GetUserName(User)))
                    {
                        model.PostAccess  = false;
                        model.PostMessage = SiteConfig.generalLocalizer["_authentication_failed"];
                        return(View(model));
                    }
                }
                var _lst = await ForumTopicBLL.LoadItems(_context, new ForumTopicEntity()
                {
                    id      = model.TopicID,
                    loadall = true
                });

                if (_lst.Count > 0)
                {
                    model.Title   = _lst[0].title;
                    model.Tags    = _lst[0].tags;
                    model.ForumID = _lst[0].forumid;
                    string desc = _lst[0].description;
                    model.Description = _lst[0].description;
                }
                else
                {
                    model.ReplyID = 0;
                    model.Message = SiteConfig.forumLocalizer["_forum_post_msg_01"].Value; //  "No existing topic found to post reply, add new topic"
                    return(View(model));
                }
            }

            if (model.ReplyID > 0)
            {
                model.HeadingTitle = SiteConfig.forumLocalizer["_post_reply"].Value;
            }
            else if (TopicID > 0)
            {
                model.HeadingTitle = "Update Post";
            }
            else
            {
                model.HeadingTitle = SiteConfig.forumLocalizer["_post_new_topic"].Value;
            }


            ViewBag.title = model.HeadingTitle;
            return(View(model));
        }