示例#1
0
        public async Task <int> AddPost(Post post)
        {
            _postsRepository.Add(post);
            await _postsRepository.UnitOfWork.SaveChangesAsync();

            return(post.PostId);
        }
示例#2
0
        /// <summary>
        /// Adds a post to the database.
        /// </summary>
        /// <param name="posterId"></param>
        /// <param name="post"></param>
        /// <param name="tagIds"></param>
        public async Task <PostModel> Add(HttpRequest httpRequest, string token, string path)
        {
            try
            {
                PostModel     post = CreatePost(httpRequest["Content"], httpRequest["IsPublic"]);
                List <TagDto> tags = GetTags(httpRequest);
                post.ImgUrl = await GetImageUrl(httpRequest.Files["Pic"], path);

                var userId = await _commonOperationsManager.VerifyToken(token).ConfigureAwait(false);

                post.Id         = GenerateId();
                post.WriterName = await GetFullName(token);

                var addedPost = await _postsRepository.Add(userId, post, tags);

                tags?.ForEach(async(tag) => {
                    try
                    {
                        string myUsername = await GetFullName(token);
                        await _commonOperationsManager.SendNotification(tag.Id, $"You were taged in a post by {myUsername}", token);
                    }
                    catch (Exception e)
                    {
                        //Log/Handle notification was not sent. Does not affect general state of like operation.
                    }
                });

                return(addedPost);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
示例#3
0
        public IActionResult Posts([FromBody] PostDetail item)
        {
            var result = _postsRepository.Add(item);

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
示例#4
0
        public IActionResult AddPost(PostDto post)
        {
            post.CreatedOn = DateTime.UtcNow;
            _postsRepository.Add(post);

            var posts = _postsRepository.GetAll();
            var model = new GuestbookViewModel()
            {
                AllPosts = posts
            };

            return(View("Index", model));
        }
示例#5
0
        public async Task CreatePost(CreatePostBlogViewModel postBlog)
        {
            var post = new Post();

            post.Title       = postBlog.Title;
            post.Content     = postBlog.Content;
            post.Author      = postBlog.Author;
            post.Description = postBlog.Description;
            post.CategoryId  = postBlog.CategoriesId;
            post.AuthorId    = postBlog.AuthorId;
            await _postsRepository.Add(post);

            await _postsRepository.SaveChanges();
        }
示例#6
0
        public IActionResult Create([FromBody] BlogPostSubmission submission)
        {
            var userId = HttpContext.GetUserId();

            if (submission == null || userId == null)
            {
                return(BadRequest());
            }

            var blogPost = new BlogPost(_random.NextPositiveLong(), userId.Value, submission);

            _posts.Add(blogPost);

            return(CreatedAtRoute("GetBlogPost", new { id = blogPost.Id }, blogPost));
        }
示例#7
0
        public Posts AddPost(PostDto postDto)
        {
            if (postDto.PhotoUploaded.Length == 0)
            {
                throw new FlowException("Please choose photo!");
            }
            else if (postDto.Description.Length > 100)
            {
                throw new FlowException("Description length must be max 100 chars!");
            }

            var post = DTOtoModel.PostDTOtoPost(postDto);

            _postsRepository.Add(post);
            _postsRepository.SaveEntities();

            return(post);
        }
示例#8
0
        /// <summary>
        /// Checks availabilty to crate post and does the creation uppon result
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public bool AddPost(CreatePostRequest request)
        {
            var user = _usersRepository.Get(request.UserName);

            if (user != null && user.RoleId == (int)Roles.Writer)
            {
                var insertedId = _postsRepository.Add(new PostDTO
                {
                    CreatedDate = DateTime.Now,
                    StatusId    = (int)PostStatuses.Created,
                    Text        = request.Text,
                    UserId      = user.Id
                });

                return(insertedId > 0);
            }

            return(false);
        }
        public async Task <Post> CreatePost([Service] IPostsRepository repository, Post model)
        {
            await repository.Add(model);

            return(model);
        }