public IActionResult AddComment([FromBody] AddCommentRequestModel comment)
        {
            //string UserId = "439e896d-d4d4-4c3e-937c-cd45d6f63dfe"; //temp
            string UserId = UserManagerRepo.GetUserId(User);
            //string UserId = "1"; //temp

            var newComment = new Comment()
            {
                Content  = comment.Content,
                GroupId  = null,
                ReplyTo  = null,
                ThreadId = comment.ThreadId,
                UserId   = UserId
            };

            Repo.Add(newComment);
            if (Repo.SaveChanges() > 0)
            {
                //return Json(new {Success = true});
                return(Json(newComment));                        //rem map to viewmodel
            }
            return(BadRequest(new { Errors = "" }));

            /*try{
             *  Repo.SaveChanges();
             * }catch(DbUpdateException e){
             *  return BadRequest(new {Errors = e.InnerException.Message} );
             * }
             * return Json(new {Success = true});*/
        }
Beispiel #2
0
        public async Task <IActionResult> GetUserDataAsync()
        {
            string UserId   = Repo.GetUserId(User);
            var    UserData = await Repo.GetUserAsync(User);

            return(Json(new {
                UserId = UserId,
                Username = UserData?.UserName
            }));
        }