Exemple #1
0
        public async Task <IActionResult> AddPagePost([Bind("Title,Text")] PagePost newPost)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user != null)
            {
                if (ModelState.IsValid)
                {
                    newPost.Date = DateTime.Now;
                    var userRoles = await _context.ApplicationUserRoles.Where(ar => ar.ApplicationUserId == user.Id).Include(ar => ar.ApplicationRole).ToListAsync();

                    foreach (var item in userRoles)
                    {
                        if (item.ApplicationRole != null)
                        {
                            if (item.ApplicationRole.Name == Role.Master)
                            {
                                _context.Add(newPost);
                                await _context.SaveChangesAsync();

                                break;
                            }
                        }
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public IRequisiteCmd GetMethod()
        {
            string bodyJson = body != null?body.ToString() : null;

            IRequisiteCmd requisiteCmd = null;

            switch (operationTable)
            {
            case OperateTable.PagePost:
                var page = new Page();
                try
                {
                    page = JsonHelper.JsonDeserilize <Page>(bodyJson);
                }
                catch (Exception e) { }
                PagePost pagePost = new PagePost(page, Db);
                requisiteCmd = pagePost as IRequisiteCmd;
                break;

            case OperateTable.NewsItemPost:
                var newsItem = new NewsItem();
                try
                {
                    newsItem = JsonHelper.JsonDeserilize <NewsItem>(bodyJson);
                }
                catch (Exception e) { }
                NewsItemPost newsItemPost = new NewsItemPost(newsItem, Db);
                requisiteCmd = newsItemPost as IRequisiteCmd;
                break;

            case OperateTable.NewsDetailPost:
                var newsDetail = new NewsDetail();
                try
                {
                    newsDetail = JsonHelper.JsonDeserilize <NewsDetail>(bodyJson);
                }
                catch (Exception e) { }
                NewsDetailPost newsDetailPost = new NewsDetailPost(newsDetail, Db);
                requisiteCmd = newsDetailPost as IRequisiteCmd;
                break;

            case OperateTable.MediaPost:
                var media = new Media();
                try
                {
                    media = JsonHelper.JsonDeserilize <Media>(bodyJson);
                }
                catch (Exception e) { }
                MediaPost mediaPost = new MediaPost(media, Db);
                requisiteCmd = mediaPost as IRequisiteCmd;
                break;

            default:
                break;
            }
            return(requisiteCmd);
        }
Exemple #3
0
        /// <summary>
        /// 渲染文章列表或文章详情页
        /// </summary>
        /// <param name="obj"></param>
        public string RenderPageOrPost(int page, long post)
        {
            PagePost type = PagePost.NONE;

            #region 参数验证
            if (page < 0)
            {
                page = 0;
            }
            if (post < 0)
            {
                post = 0;
            }

            if (page == 0 && post == 0)
            {
                page = 1;
                post = 0;
            }
            if (page > 0 && post > 0)
            {
                post = 0;
            }
            if (page > 0)
            {
                type = PagePost.PAGE;
            }
            if (post > 0)
            {
                type = PagePost.POST;
            }
            #endregion

            string topTmpl    = ResourceHelper.LoadStringResource("top.html");
            string bottomTmpl = ResourceHelper.LoadStringResource("bottom.html");

            string GetNoPostsHtml()
            {
                StringBuilder sbHtmlNoPosts = new StringBuilder();

                sbHtmlNoPosts.AppendLine(topTmpl.AsHtmlFromTemplate(new
                {
                    Configuration = _tinyConfiguration
                }));

                sbHtmlNoPosts.Append("<article class=\"post\"><div class=\"post__main echo\">你来到了没有知识的荒原...</div></article>");

                sbHtmlNoPosts.AppendLine(bottomTmpl.AsHtmlFromTemplate(new
                {
                    Configuration = _tinyConfiguration
                }));

                return(sbHtmlNoPosts.ToString());
            }

            string GetPageHtml()
            {
                int maxPage = int.MaxValue;

                var pageData = _pressService.GetPostInPage(page, ref maxPage, false, _tinyConfiguration.PageSize);

                if (page > maxPage)
                {
                    page = maxPage;
                }

                if (pageData == null || pageData.Count() < 1)
                {
                    return(GetNoPostsHtml());
                }

                StringBuilder sbHtml = new StringBuilder();

                sbHtml.AppendLine(topTmpl.AsHtmlFromTemplate(new
                {
                    BrowserTitle  = _tinyConfiguration.SiteName,
                    Description   = _tinyConfiguration.SiteName,
                    Configuration = _tinyConfiguration
                }));

                string pageTmpl  = ResourceHelper.LoadStringResource("page.html");
                string pagerTmpl = ResourceHelper.LoadStringResource("pager.html");

                foreach (var item in pageData)
                {
                    string content = item.Content.AsPlainTextFromMarkdown();

                    if (content.Length < 1)
                    {
                        content = item.Title;
                    }
                    if (content.Length > (TinyfxCore.MAX_POST_DESCRIPTION_LENGTH + 10))
                    {
                        content = content.Substring(0, TinyfxCore.MAX_POST_DESCRIPTION_LENGTH) + "...";
                    }

                    sbHtml.AppendLine(pageTmpl.AsHtmlFromTemplate(new
                    {
                        Date          = new DateTime(item.Id).ToString(),
                        Pid           = item.Id,
                        Title         = item.Title,
                        Content       = content.AsHtmlEncode(),
                        Configuration = _tinyConfiguration
                    }));
                }

                string PrevPage = null;
                string NextPage = null;

                if (page - 1 > 0)
                {
                    PrevPage = (page - 1).ToString();
                }

                if (page + 1 <= maxPage)
                {
                    NextPage = (page + 1).ToString();
                }


                sbHtml.AppendLine(pagerTmpl.AsHtmlFromTemplate(new
                {
                    PrevPage      = PrevPage,
                    NextPage      = NextPage,
                    TotalPage     = maxPage,
                    CurrentPage   = page,
                    Configuration = _tinyConfiguration
                }));

                sbHtml.AppendLine(bottomTmpl.AsHtmlFromTemplate(new
                {
                    Configuration = _tinyConfiguration
                }));

                return(sbHtml.ToString());
            }

            string GetPostHtml()
            {
                var postItem = _pressService.GetPostByID(post, false);

                if (postItem == null)
                {
                    return(GetNoPostsHtml());
                }

                StringBuilder sbHtml = new StringBuilder();

                sbHtml.Append(topTmpl.AsHtmlFromTemplate(new
                {
                    BrowserTitle  = postItem.Title + " - " + _tinyConfiguration.SiteName,
                    Description   = postItem.Title,
                    SiteLink      = "/",
                    Configuration = _tinyConfiguration
                }));

                string postTmpl = ResourceHelper.LoadStringResource("post.html");

                sbHtml.Append(postTmpl.AsHtmlFromTemplate(new
                {
                    Date          = new DateTime(postItem.Id).ToString(),
                    Pid           = postItem.Id,
                    Title         = postItem.Title,
                    Content       = postItem.Content.AsHtmlFromMarkdown(),
                    Configuration = _tinyConfiguration
                }));

                sbHtml.Append(bottomTmpl.AsHtmlFromTemplate(new
                {
                    SiteName      = _tinyConfiguration.SiteName,
                    Configuration = _tinyConfiguration
                }));

                return(sbHtml.ToString());
            }

            if (type == PagePost.PAGE)
            {
                return(GetPageHtml());
            }
            else if (type == PagePost.POST)
            {
                return(GetPostHtml());
            }
            else
            {
                return(GetNoPostsHtml());
            }
        }
Exemple #4
0
        public static void Initialize(ApplicationDbContext context)
        {
            context.Database.EnsureCreated();
            if (context.PagePosts.Any())
            {
                return;
            }
            var PagePosts = new PagePost[]
            {
                new PagePost
                {
                    Title = "Pierwszy post na portalu",
                    Text  = "Witam wszystkich zebranych",
                    Date  = new DateTime(2018, 1, 10, 10, 20, 20)
                },
                new PagePost
                {
                    Title = "Drugi post na portalu",
                    Text  = "Witam wszystkich zebranych",
                    Date  = new DateTime(2018, 1, 12, 10, 20, 20)
                },
                new PagePost
                {
                    Title = "Trzeci post na portalu",
                    Text  = "No siema",
                    Date  = new DateTime(2018, 1, 16, 10, 20, 20)
                },
                new PagePost
                {
                    Title = "Czwarty post na portalu",
                    Text  = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sodales nulla nisi, sit amet efficitur nisl tristique non. Donec ut dui faucibus nulla aliquam pulvinar vel in turpis. Proin malesuada malesuada tincidunt. Phasellus molestie erat nec arcu blandit mollis. Cras vitae nisl rutrum, tempor mauris at, suscipit libero. Nulla fermentum diam at purus imperdiet, nec efficitur massa imperdiet. Sed posuere ligula porttitor nibh tempus posuere. Nulla molestie dignissim lorem, vel semper enim aliquet nec. Donec convallis tellus ac venenatis tempor. Nulla vitae tellus cursus, feugiat nisl eget, bibendum quam. /n Etiam elementum hendrerit massa a consequat. Vestibulum iaculis sem quis turpis pharetra, eget ultrices elit maximus. Mauris ultricies, dui non bibendum consequat, urna est eleifend est, fringilla venenatis nunc lorem sed turpis. Vestibulum fermentum auctor justo, non pulvinar massa. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed a neque interdum, cursus lacus eu, luctus velit. Suspendisse lectus ante, consequat et sollicitudin ac, pretium vitae nunc. Duis finibus erat in risus ullamcorper, ut facilisis enim convallis. Phasellus sodales lorem neque, ac efficitur ipsum tempor porta. Aenean sed lacinia ipsum, fermentum sodales nisl. Sed a libero et nunc finibus semper at ac enim. Nulla finibus nisl in arcu porttitor fringilla. Quisque fringilla purus at lectus egestas, id pharetra nisl interdum.",
                    Date  = new DateTime(2018, 1, 20, 20, 20, 20)
                }
            };

            foreach (PagePost pp in PagePosts)
            {
                context.PagePosts.Add(pp);
            }

            var countries = new Country[]
            {
                new Country
                {
                    name = "Poland"
                }
            };

            foreach (Country c in countries)
            {
                context.Countries.Add(c);
            }

            var regions = new Region[]
            {
                new Region
                {
                    Name    = "Mazowieckie",
                    Country = countries[0]
                },
                new Region
                {
                    Name    = "Warmińsko-mazurskie",
                    Country = countries[0]
                }
            };

            foreach (Region r in regions)
            {
                context.Regions.Add(r);
            }

            var dropzones = new Dropzone[]
            {
                new Dropzone
                {
                    Name    = "SkyDive Warszawa",
                    Region  = regions[0],
                    Address = "05-190 Nasielsk, Lotnisko Chrcynno"
                },
                new Dropzone
                {
                    Name    = "Strefa Baltic",
                    Region  = regions[1],
                    Address = "82-300 Elbląg, ul. Lotnicza 8b"
                }
            };

            foreach (Dropzone d in dropzones)
            {
                var roles = new ApplicationRole[]
                {
                    new ApplicationRole
                    {
                        Dropzone = d,
                        Name     = Role.Admin
                    },
                    new ApplicationRole
                    {
                        Dropzone = d,
                        Name     = Role.Moderator
                    }
                };
                foreach (ApplicationRole ar in roles)
                {
                    context.ApplicationRoles.Add(ar);
                }
                context.Dropzones.Add(d);
            }

            var role = new ApplicationRole()
            {
                Name = Role.Master
            };

            context.ApplicationRoles.Add(role);

            context.SaveChanges();
        }