예제 #1
0
        public async Task <IActionResult> OnPostAsync(string blogAddress)
        {
            try
            {
                CurBlog = db.Blogs.Where(p => p.Address == blogAddress).First();
            }
            catch
            {
                return(StatusCode(404));
            }
            if (ModelState.IsValid)
            {
                var tags = Input.Tags?.Split(';');
                var url  = string.Join("-", new string[] { DateTime.Now.ToString("yyyy-MM-dd"), Input.Title.GetHashCode().ToString() });
                //TODO: check if this url already exists
                var post = new Domain.Post {
                    BlogId = CurBlog.Id, Title = Input.Title, Content = Input.Content, Tags = tags, Url = url
                };
                db.Posts.Add(post);
                await db.SaveChangesAsync();

                _logger.LogInformation("User created a new post.");
                return(RedirectToPage($"/Blog/Index", new { address = CurBlog.Address }));
            }
            return(Page());
        }
예제 #2
0
        public async Task <CreateBlogResponse> Handle(CreateBlogRequestMsg message)
        {
            var validationResult = _createBlogValidator.Validate(message);

            if (validationResult.IsValid == false)
            {
                return(await Task.FromResult(new CreateBlogResponse(Guid.Empty, validationResult)));
            }

            var blog = new Domain.Blog
            {
                Title            = message.Title,
                Description      = message.Description,
                Theme            = message.Theme,
                PostsPerPage     = message.PostsPerPage,
                DaysToComment    = message.DaysToComment,
                ModerateComments = message.ModerateComments
            };
            var blogCreated = await _blogRepo.AddAsync(blog);

            // raise events
            foreach (var @event in blog.Events)
            {
                await _mediator.Publish(@event);
            }

            return(await Task.FromResult(new CreateBlogResponse(blogCreated.Id, validationResult)));
        }
예제 #3
0
        public List <Domain.Blog> GetBlogs()
        {
            List <Domain.Blog> list = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Blogs_SelectAll"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
            }
                                    , map : delegate(IDataReader reader, short set)
            {
                Domain.Blog p     = new Domain.Blog();
                int startingIndex = 0;

                p.Id          = reader.GetSafeInt32(startingIndex++);
                p.Title       = reader.GetSafeString(startingIndex++);
                p.PublishDate = reader.GetSafeDateTime(startingIndex++);
                p.UserId      = reader.GetSafeString(startingIndex++);
                p.PageContent = reader.GetSafeString(startingIndex++);
                p.Slug        = reader.GetSafeString(startingIndex++);

                if (list == null)
                {
                    list = new List <Domain.Blog>();
                }

                list.Add(p);
            }
                                    );
            return(list);
        }
예제 #4
0
        public Domain.Blog GetBlogBySlug(string slug)
        {
            Domain.Blog p = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.WebsiteBlogs_SelectByBlogSlug"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Slug", slug);
            }, map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    p = new Domain.Blog();
                    int startingIndex = 0;

                    p.Id          = reader.GetSafeInt32(startingIndex++);
                    p.Title       = reader.GetSafeString(startingIndex++);
                    p.PublishDate = reader.GetSafeDateTime(startingIndex++);
                    p.UserId      = reader.GetSafeString(startingIndex++);
                    p.PageContent = reader.GetSafeString(startingIndex++);
                    p.Slug        = reader.GetSafeString(startingIndex++);
                    p.IsFeatured  = reader.GetSafeBool(startingIndex);
                    p.BMedia      = new List <BlogMedia>();
                }
                else if (set == 1)
                {
                    BlogMedia x       = new BlogMedia();
                    int startingIndex = 0;

                    x.BlogId       = reader.GetSafeInt32(startingIndex++);
                    x.IsCoverPhoto = reader.GetSafeBool(startingIndex++);
                    x.MediaType    = reader.GetSafeString(startingIndex++);
                    x.Path         = reader.GetSafeString(startingIndex++);
                    x.FileName     = reader.GetSafeString(startingIndex++);
                    x.FileType     = reader.GetSafeString(startingIndex++);
                    x.Title        = reader.GetSafeString(startingIndex++);
                    x.Description  = reader.GetSafeString(startingIndex++);
                    x.UserID       = reader.GetSafeString(startingIndex++);
                    x.CreatedDate  = reader.GetSafeDateTime(startingIndex++);
                    x.ModifiedDate = reader.GetSafeDateTime(startingIndex++);
                    x.ID           = reader.GetSafeInt32(startingIndex++);

                    p.BMedia.Add(x);
                    if (x.IsCoverPhoto == true)
                    {
                        p.Media = x;
                    }
                }
            }
                                    );


            return(p);
        }
예제 #5
0
        public List <Domain.Blog> ListBlogsByWebsiteId(PaginateListRequestModel model, int websiteId)
        {
            List <Domain.Blog> list = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.WebsiteBlogs_ListBlogsByWebsiteId"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@CurrentPage", model.CurrentPage);
                paramCollection.AddWithValue("@ItemsPerPage", model.ItemsPerPage);
                paramCollection.AddWithValue("@websiteId", websiteId);
            }
                                    , map : delegate(IDataReader reader, short set)
            {
                Domain.Website w    = new Domain.Website();
                Domain.Blog p       = new Domain.Blog();
                Domain.BlogMedia bm = new Domain.BlogMedia();

                int startingIndex = 0;

                w.ID          = reader.GetSafeInt32(startingIndex++);
                p.Id          = reader.GetSafeInt32(startingIndex++);
                p.Title       = reader.GetSafeString(startingIndex++);
                p.PublishDate = reader.GetSafeDateTime(startingIndex++);
                p.Slug        = reader.GetSafeString(startingIndex++);
                p.UserId      = reader.GetSafeString(startingIndex++);
                p.PageContent = reader.GetSafeString(startingIndex++);
                p.IsFeatured  = reader.GetSafeBool(startingIndex++);

                bm.BlogId        = reader.GetSafeInt32(startingIndex++);
                bm.IsCoverPhoto  = reader.GetSafeBool(startingIndex++);
                bm.ID            = reader.GetSafeInt32(startingIndex++);
                bm.MediaType     = reader.GetSafeString(startingIndex++);
                bm.Path          = reader.GetSafeString(startingIndex++);
                bm.FileName      = reader.GetSafeString(startingIndex++);
                bm.FileType      = reader.GetSafeString(startingIndex++);
                bm.Title         = reader.GetSafeString(startingIndex++);
                bm.Description   = reader.GetSafeString(startingIndex++);
                bm.CreatedDate   = reader.GetSafeDateTime(startingIndex++);
                bm.ModifiedDate  = reader.GetSafeDateTime(startingIndex++);
                bm.ThumbnailPath = reader.GetSafeString(startingIndex++);
                p.Media          = bm;

                if (list == null)
                {
                    list = new List <Domain.Blog>();
                }

                list.Add(p);
            });
            return(list);
        }
예제 #6
0
        public List <Domain.Blog> GetBlogsLatestToOldest(PaginateListRequestModel model)
        {
            List <Domain.Blog> list = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Blog_Listingstwo"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@CurrentPage", model.CurrentPage);
                paramCollection.AddWithValue("@ItemsPerPage", model.ItemsPerPage);
            }
                                    , map : delegate(IDataReader reader, short set)
            {
                Domain.Blog p       = new Domain.Blog();
                Domain.BlogMedia bm = new Domain.BlogMedia();
                int startingIndex   = 0;

                p.Id            = reader.GetSafeInt32(startingIndex++);
                p.Title         = reader.GetSafeString(startingIndex++);
                p.PublishDate   = reader.GetSafeDateTime(startingIndex++);
                p.UserId        = reader.GetSafeString(startingIndex++);
                p.PageContent   = reader.GetSafeString(startingIndex++);
                p.Slug          = reader.GetSafeString(startingIndex++);
                bm.BlogId       = reader.GetSafeInt32(startingIndex++);
                bm.IsCoverPhoto = reader.GetSafeBool(startingIndex++);
                bm.ID           = reader.GetSafeInt32(startingIndex++);
                bm.MediaType    = reader.GetSafeString(startingIndex++);
                bm.Path         = reader.GetSafeString(startingIndex++);
                bm.FileName     = reader.GetSafeString(startingIndex++);
                bm.FileType     = reader.GetSafeString(startingIndex++);
                bm.Title        = reader.GetSafeString(startingIndex++);
                bm.Description  = reader.GetSafeString(startingIndex++);

                if (list == null)
                {
                    list = new List <Domain.Blog>();
                }
                if (bm.ID == 0)
                {
                    p.Media = null;
                }

                else
                {
                    p.Media = bm;
                }
                list.Add(p);
            });
            return(list);
        }
예제 #7
0
        public async Task <IActionResult> OnGetAsync(string blogAddress)
        {
            try
            {
                CurBlog = db.Blogs.Where(p => p.Address == blogAddress).First();
            }
            catch
            {
                return(StatusCode(404));
            }

            var user = await _userManager.GetUserAsync(_httpContextAccessor.HttpContext.User);

            if (user.Id != CurBlog.AuthorId)
            {
                return(StatusCode(403));
            }
            return(Page());
        }
예제 #8
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var sameAddress = db.Blogs.Where(p => p.Address == Input.Address);
                if (sameAddress.Count() > 0)
                {
                    ModelState.AddModelError(string.Empty, "Sorry, this blog address is not available.");
                    return(Page());
                }
                var user = await _userManager.GetUserAsync(_httpContextAccessor.HttpContext.User);

                var blog = new Domain.Blog {
                    AuthorId = user.Id, Title = Input.Title, Address = Input.Address
                };
                db.Blogs.Add(blog);
                await db.SaveChangesAsync();

                _logger.LogInformation("User created a new blog.");
                return(RedirectToPage($"/Blog/Index", new { address = blog.Address }));
            }
            return(Page());
        }