public async Task <IActionResult> AddStudentQuestion([FromBody] Question newQuestion) { //Get Request's User var claimsIdentity = (ClaimsIdentity)this.User.Identity; if (!claimsIdentity.IsAuthenticated) { return(Unauthorized()); } //Get Student Profile var claim = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier); var userEmail = claim.Value; var User = await _userManager.FindByEmailAsync(userEmail); newQuestion.UserId = User.Id; newQuestion.Likes = 0; newQuestion.Dislikes = 0; var Question = _profileSrv.AddQuestion(newQuestion); var studentData = _profileSrv.GetStudent(User.Id); //SignalR Layer . // This Layer Should Be In Try Catch Ex. Handler Beacuse App Shoul Work If SignalR Service Working or Not. //try //{ // // 1) Get List Of Followings Connections Ids . // var Follower = _profileSrv.GetStudentFriends(User.Id).Select(u=> u.FriendTwoId).ToList(); // var Connections = _signalrSrv.GetConnectionsByUserId(Follower).ToList(); // // 2) Get Question Object . // // 3) Call SignalR Api Pass Parameters To It . // using (var client = new HttpClient()) // { // NewQuestionSignalrVM model = new NewQuestionSignalrVM() { // Connection = Connections, // QuestionHead = Question.QuestionHead, // Id = Question.Id, // Username = User.Name, // Image = studentData.Image, // UserId = studentData.ApplicationUserId, // Title = studentData.Title, // Date = Question.Date, // Answers = null // }; // var modelToJson = JsonConvert.SerializeObject(model); // var content = new StringContent(modelToJson, Encoding.UTF8, "application/json"); // var result = client.PostAsync("http://localhost:10724/api/signalr/newquestion", content).Result; // } //} //catch //{ // //IGnore //} return(Ok(new { Status = "Success", Question = new { QuestionHead = Question.QuestionHead, Id = Question.Id, Username = User.Name, Image = studentData.Image, UserId = studentData.ApplicationUserId, Title = studentData.Title, Date = Question.Date, Answers = new object[0] } })); }
public async Task <IActionResult> AddStudentQuestion([FromBody] Question newQuestion) { //Get Request's User var claimsIdentity = (ClaimsIdentity)this.User.Identity; if (!claimsIdentity.IsAuthenticated) { return(Unauthorized()); } //Get Student Profile var claim = claimsIdentity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier); var userEmail = claim.Value; var User = await _userManager.FindByEmailAsync(userEmail); newQuestion.UserId = User.Id; newQuestion.Likes = 0; newQuestion.Dislikes = 0; var Question = _profileSrv.AddQuestion(newQuestion); try { return(Ok(new { Status = "Success", Question = new { QuestionHead = Question.QuestionHead, QuestionId = Question.Id, Likes = Question.Likes, Dislikes = Question.Dislikes //, // Answers = // from a in Question.Answers // select new // { // Answer = a.QuestionAnswer, // AnswerId = a.Id, // UserId = a.UserId, // Username = a.User.Name, // UserImage = _profileSrv.GetStudentProfile(User).Image // }//End Answers } //End Questions } //End Response Object )); } catch { return(Ok(new { Status = "Success", Question = new { QuestionHead = Question.QuestionHead, QuestionId = Question.Id, Likes = Question.Likes, Dislikes = Question.Dislikes , Answers = new { } } //End Questions } //End Response Object )); } }