public async Task <IActionResult> PostAComment(int id, string commentText) { //Gets the current user AppUser currentUser = await _appUserManager.GetUserAsync(User); //Gets specified post Post commentedPost = await _postRepository.GetSingle(id); //So time matches in different tables var currentDateTime = DateTime.Now; //Creates new CommentModel instance var newCommentModel = new CommentModel { Commentator = currentUser.ToAppUserModelBaseInfo(), Content = commentText, TimeOfCommenting = currentDateTime, AppUserId = commentedPost.AppUserId, PostId = id }; //Adds Comment entity to database await _commentRepository.Add(newCommentModel.ToCommentEntity()); //Creates new NotificationModel instance (to take advantage of strategy pattern) and converts it to Notification entity Notification newNotification = new NotificationModel(currentUser.FirstName, currentUser.LastName, currentDateTime, id, new CommentNotificationTextBehavior()) .ToNotificationEntity(currentUser.Id, commentedPost.AppUserId); //Adds new notification to the database await _notificationRepository.Add(newNotification); return(Json(newCommentModel)); }