public IActionResult ReplyToComment(int contentId, int id, [FromBody] CreateCommentForRemap reply) { // super try { if (_user != null || _admin != null) { if (reply.Message.Contains('#') || reply.Message.Contains('@')) { var user = new AvatarEntity(); var sentence = " " + reply.Message; int userid = (int)reply.AvatarId; var results = _ctx.DetectObjectType(sentence, contentId, userid); // if(result != null) // { // user = (AvatarEntity)result[0]; // _logger.LogInformation($"This is the result - {user.Name} - {user.Id}"); // } } if (_user != null) { reply.AvatarId = _user.Id; } if (_admin != null) { reply.IsSuperUser = _admin.Id; } var comment = _ctx.GetCommentById(id); reply.PostedOn = DateTime.Now; reply.CardEntityId = contentId; reply.ReplyToCommentId = id; reply.ResponseToAvatarId = comment.AvatarId; var result = _mapper.Map <CommentEntity>(reply); if (_user != null) { if (_ctx.AddCommentByUser(result, _user.Id, commentIdToAddOn: id)) { return(Ok($"Reply had been added by USER: {_user.Id} comment:{id}.")); } } if (_admin != null) { if (_ctx.AddCommentByUser(result, admin: _admin.Id, commentIdToAddOn: id)) { return(Ok($"Reply had been added by ADMIN on comment:{id}.")); } } return(NotFound($"No REPLY has been added to comment ID:{id}")); } return(Unauthorized(Message("unautherized"))); } catch (Exception ex) { _logger.LogError($"Unable to create reply on comment: {id}.", ex); return(StatusCode(500, "There was an expection found at RepltToComment.")); } }
public IActionResult CreateComment(int contentId, [FromBody] CreateCommentForRemap createdComment) { try { if (_user != null || _admin != null) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (createdComment.Message.Contains('#') || createdComment.Message.Contains('@')) { var user = new AvatarEntity(); var sentence = " " + createdComment.Message; int id = _user.Id; /*(int)createdComment.AvatarId; */ var result = _ctx.DetectObjectType(sentence, contentId, id); // if(result != null) // { // user = (AvatarEntity)result[0]; // _logger.LogInformation($"This is the result - {user.Name} - {user.Id}"); // } } if (_admin != null) { createdComment.IsSuperUser = _admin.Id; createdComment.AvatarId = null; } if (_user != null) { createdComment.IsSuperUser = null; createdComment.AvatarId = _user.Id; } createdComment.LastUpdatedOn = DateTime.Now; createdComment.PostedOn = DateTime.Now; createdComment.CardEntityId = contentId; var date = createdComment.PostedOn; var finalComment = new CommentEntity(); _ctx.AddCommentByUser(_mapper.Map <CommentEntity>(createdComment)); // if (_admin != null) { var dbResult = _ctx.GetCommentsByAvatar(admin: _admin.Id); finalComment = dbResult.Where(p => p.PostedOn == date).FirstOrDefault(); } if (_user != null) { var dbResult = _ctx.GetCommentsByAvatar(id: _user.Id); finalComment = dbResult.Where(p => p.PostedOn == date).FirstOrDefault(); } return(CreatedAtRoute( "GetComment", new { contentId, id = finalComment.Id }, finalComment )); } return(BadRequest("No User is Logged in")); } catch (Exception ex) { _logger.LogError($"Unable to create a comment on card: {contentId}.", ex); return(StatusCode(500, "There was an expection found at CreateComment.")); } }