/// <summary> /// Adds comment to the post associated with the post id /// extracted from the http request. /// </summary> /// <param name="httpRequest"></param> /// <param name="token"></param> /// <param name="path"></param> /// <returns></returns> public async Task <CommentModel> AddComment(HttpRequest httpRequest, string token, string path) { try { string userId = await _commonOperationsManager.VerifyToken(token); string postId = httpRequest["PostId"]; List <TagDto> tags = GetTags(httpRequest); CommentModel comment = CreateComment(httpRequest["Content"]); comment.ImgUrl = await GetImageUrl(httpRequest.Files["Pic"], path); var addedComment = await _postsRepository.AddComment(userId, postId, comment, tags); try { var postUser = await _postsRepository.GetPostUser(postId); string myUsername = await GetFullName(token); await _commonOperationsManager.SendNotification(postUser.Id, $"{myUsername} commented on one of your posts", token); } catch (Exception e) { //Log/Handle notification was not sent. Does not affect general state of like operation. } return(addedComment); } catch (Exception e) { throw; } }