Beispiel #1
0
		/// <summary>
		/// Adding to blogpost user id and calls method that saves post to db
		/// </summary>
		/// <param name="post"></param>
		/// <returns>New post id</returns>
		public async Task<int> NewBlogPost(Post post)
		{
			var user = await _authRepo.FindByUsername(post.Username);
			if (!string.IsNullOrEmpty(user.Id))
				post.UserId = user.Id;

			var newPostId = await _repo.NewBlogPost(post);

			return newPostId;
		}
Beispiel #2
0
		public async Task<int> NewBlogPost(Post post)
		{
			context.Posts.Add(post);

			foreach(var item in post.Paragraphs) {
				context.Paragraphs.Add(item);
			}

			await context.SaveChangesAsync();
			return post.Id;
		}
Beispiel #3
0
        /// <summary>
        /// Converts post to blogpostdto
        /// </summary>
        /// <param name="post"></param>
        /// <returns>object of blogpostdto</returns>
        public BlogPostDTO ConvertPostToDTO(Post post)
        {
            var result = new BlogPostDTO
            {
                Id = post.Id,
                PostTime = post.PostTime,
                Title = post.Title,
                Paragraphs = post.Paragraphs,
                Username = post.Username
            };

            return result;
        }
Beispiel #4
0
        /// <summary>
        /// Converts created post to post object
        /// </summary>
        /// <param name="postDto"></param>
        /// <returns>Post object</returns>
        public Post ConvertDtoToPost(CreatePostDTO postDto)
        {
            var result = new Post
            {
                Title = postDto.Title,
                PostTime = DateTime.Now,
                Paragraphs = postDto.Paragraphs,
                Username = postDto.Username,
                Publish = postDto.Publish
            };

            return result;
        }