public async Task <IActionResult> AddBlogAsync([FromBody] PostBlogDTO model) { try { var post = new PostBlog { Name = model.Name, DateOfCreation = model.DateOfCreation, Plot = model.Plot }; var userId = caller.Claims.Single(c => c.Type == "id"); //var customer = await appDbContext.UserInfoes.Include(c => c.Identity).SingleAsync(c => c.Identity.Id == userId.Value); var user = await unitOfWork.Users.GetUserByIdentityId(userId.Value); var trip = await unitOfWork.Trips.GetTripByIdAsync(model.TripId); var isUserCreator = unitOfWork.Trips.IsUserCreator(user.Id, trip.Id); if (!isUserCreator) { return(Forbid()); } post.Trip = trip; unitOfWork.PostBlogs.Add(post); logger.LogInfo($"Add some post"); return(Ok(model)); } catch (Exception ex) { logger.LogError($"Something went wrong inside AddBlogAsync;{ex.Message}"); return(StatusCode(500, "Internal Server Error")); } }
public async Task <string> Create(PostBlog postBlog, ObjectId userId) { var blog = new Blog(postBlog, userId); await _blogCollection.InsertOneAsync(blog); _mongoDbService.RemoveCacheFromSet(userId.ToString()); return(JsonConvert.SerializeObject(blog)); }
public async Task <IActionResult> Post([FromBody] PostBlog request) { var user = await _userManager.GetUserAsync(HttpContext.User); var response = await _blogService.Create(request, user.Id); return(Ok(response)); }
public PostBlogDetailsDTO(PostBlog postBlog) { this.Name = postBlog.Name; this.Plot = postBlog.Plot; this.DateOfCreation = postBlog.DateOfCreation; }