Beispiel #1
0
        public IActionResult FormUnsub([FromQuery] string url, [FromQuery] string boardtag = null, [FromQuery] int?threadid = null)
        {
            var             res = this.WebhooksController.UnSubscribeWebhook(url, boardtag, threadid);
            ApiActionStatus apistatus;

            if (res is BadRequestObjectResult badres)
            {
                apistatus = new ApiActionStatus()
                {
                    Message      = badres.Value.ToString(),
                    ResponseCode = 400,
                    Title        = "Webhook"
                }
            }
            ;
            else
            {
                apistatus = new ApiActionStatus()
                {
                    Message      = "Success",
                    ResponseCode = 200,
                    Title        = "Webhook"
                }
            };

            return(this.View(INDEX_PAGE_PATH, new IndexPageModel()
            {
                ActionStatus = apistatus,
                Boards = this.Database.Boards,
                Config = this.Config
            }));
        }
    }
Beispiel #2
0
        public async Task <IActionResult> Board([FromQuery] string board_tag, [FromQuery] string text, [FromQuery] int parent_id = -1, [FromQuery] string username = null, [FromQuery] string topic = null, [FromQuery] string password = null, [FromQuery] string imageurl = null, [FromQuery] long replytoid = -1)
        {
            var usr = await this.UserManager.GetUserAsync(this.User);

            var res = await this.ThreadController.CreatePost(new Thread()
            {
                BoardTag         = board_tag,
                GeneratePassword = password,
                Text             = text,
                ParentId         = parent_id,
                Username         = username ?? this.User.Identity?.Name,
                Image            = imageurl,
                ReplyToId        = replytoid,
                Topic            = topic,
                UserId           = usr?.Id ?? "-1"
            });

            if (res.Result is BadRequestObjectResult badres)
            {
                var apistatus = new ApiActionStatus()
                {
                    Message      = badres.Value.ToString(),
                    ResponseCode = 400,
                    Title        = "Post"
                };
                var boardview = (ViewResult)this.Board(board_tag, status: apistatus);
                return(this.View(BOARD_PAGE_PATH, boardview.Model));
            }
            else
            {
                return(this.LocalRedirect($"/board/{board_tag}"));
            }
        }
Beispiel #3
0
        public IActionResult Board(string tag, [FromQuery] int p = 1, ApiActionStatus status = null)
        {
            var threadcount = this.Database.Threads.Where(x => x.BoardTag == tag && x.ParentId < 1).Count();

            var pagecount = 1;
            // calculating page count
            var remainder = threadcount % MAX_THREADS_ON_INDEX;

            if (threadcount - remainder >= MAX_THREADS_ON_INDEX) // we can only have more than 1 page when we have over 10 threads
            {
                pagecount = ((threadcount - remainder) / MAX_THREADS_ON_INDEX);
                if (remainder > 0)
                {
                    pagecount++;
                }
            }

            // Get threads in order of last bumped.
            var threads = this.Database.Threads.Where(x => x.BoardTag == tag && x.ParentId < 1)
                          .OrderByDescending(x => this.Database.Threads.Where(a => a.ParentId == x.Id || a.Id == x.Id).Select(b => b.Id).Max())
                          .Skip(Math.Abs(p - 1) * MAX_THREADS_ON_INDEX)
                          .Take(MAX_THREADS_ON_INDEX)
                          .ToList();

            threads.ToList().ForEach(x =>
            {
                x.ChildThreads = this.Database.Threads.Where(a => a.ParentId == x.Id).OrderByDescending(a => a.Id).Take(5);
            });

            var bigOnes = new List <int>();

            foreach (var t in threads)
            {
                if (this.Database.Threads.Where(a => a.ParentId == t.Id).Count() > 5)
                {
                    bigOnes.Add(t.Id);
                }
            }

            return(this.View(BOARD_PAGE_PATH, new BoardPageModel()
            {
                BoardInfo = this.Database.Boards.FirstOrDefault(x => x.Tag == tag),
                Threads = threads,
                BigThreads = bigOnes,
                PageCount = pagecount,
                Currentpage = p,
                MaxThreadsPerPage = MAX_THREADS_ON_INDEX,
                Config = this.Config,
                ActionStatus = status
            }));
        }
Beispiel #4
0
        public IActionResult DeletePostFromQuery([FromQuery] int postid, [FromQuery] string password, [FromQuery] string board_tag)
        {
            var res = this.ThreadController.DeletePost(postid, password);

            if (res.Result is BadRequestObjectResult badres)
            {
                var apistatus = new ApiActionStatus()
                {
                    Message      = badres.Value.ToString(),
                    ResponseCode = 400,
                    Title        = "Delete"
                };
                var boardview = (ViewResult)this.Board(board_tag, status: apistatus);
                return(this.View(BOARD_PAGE_PATH, boardview.Model));
            }
            else
            {
                return(this.LocalRedirect($"/board/{board_tag}"));
            }
        }