Esempio n. 1
0
        public override async Task <DeleteBlogResponse> DeleteBlog(DeleteBlogRequest request, ServerCallContext context)
        {
            var blogId  = request.BlogId;
            var filter  = new FilterDefinitionBuilder <BsonDocument>().Eq("_id", new ObjectId(blogId));
            var deleted = await mongoCollection.DeleteOneAsync(filter);

            if (deleted.DeletedCount == 0)
            {
                throw new RpcException(new Status(StatusCode.NotFound, $"Blog with id={blogId} was not found"));
            }
            return(new DeleteBlogResponse {
                BlogId = blogId
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Delete Blog Method
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override async Task <DeleteBlogResponse> DeleteBlog(DeleteBlogRequest request, ServerCallContext context)
        {
            var filter = new FilterDefinitionBuilder <BsonDocument>().Eq("_id", new ObjectId(request.BlogId));

            var result = await mongoCollection.DeleteOneAsync(filter);

            if (result.DeletedCount == 0)
            {
                throw new RpcException(new Status(StatusCode.NotFound, "The blog id " + request.BlogId + " was not find"));
            }

            return(new DeleteBlogResponse()
            {
                BlogId = request.BlogId
            });
        }
Esempio n. 3
0
        public async Task <IActionResult> Delete(Guid id)
        {
            var deleteRequest = new DeleteBlogRequest()
            {
                Id       = id,
                Username = User.Identity.Name
            };

            var response = await _blogs.DeleteAsync(deleteRequest);

            if (!response.Success)
            {
                return(BadRequest(response.ErrorMessage));
            }
            var blog = response.Result;

            var readDto = _mapper.Map <BlogReadDto>(blog);

            return(Ok(readDto));
        }
Esempio n. 4
0
 public void Delete(DeleteBlogRequest request)
 {
     this._BlogManager.DeleteBlog(request.BlogId);
 }