public IActionResult GetMarking(int Uid, int Pid) { var markedPost = _repository.GetMarkingById(Uid, Pid); var newMarkingModel = new MarkingModel(); newMarkingModel.MarkingId = markedPost.MarkedPostId; newMarkingModel.UserId = markedPost.UserId; newMarkingModel.PostId = markedPost.PostId; newMarkingModel.MarkingUrl = Url.Link(nameof(GetMarking), new { Uid = markedPost.UserId, Pid = markedPost.PostId }); // Checking whether the post is an answer or question to give it the correct link newMarkingModel.PostUrl = _repository.GetPostById(markedPost.PostId).PostTypeId == 2 ? Url.Link(nameof(AnswerController.GetAnswerById), new { Qid = _repository.GetPostById(markedPost.PostId).ParentId, Aid = markedPost.MarkedPostId }) : Url.Link(nameof(QuestionController.GetQuestionById), new { Qid = markedPost.PostId }); newMarkingModel.RemoveMarking = Url.Link(nameof(RemoveMarking), new { Mid = markedPost.MarkedPostId }); // Checking whether there's annotation or not newMarkingModel.MarkingAnnotation = _repository.GetAnnotationsByMarkingId(markedPost.MarkedPostId).ToList().Select(a => new AnnotationModel { MarkingLink = Url.Link(nameof(GetMarking), new { Pid = a.MarkedPostId }), AnnotationText = a.Annotation, From = a.From, To = a.To, EditAnnotation = Url.Link(nameof(AnnotationController.EditAnnotation), new { AnnotId = a.Annotationid, text = a.Annotation }), RemoveAnnotation = Url.Link(nameof(AnnotationController.RemoveAnnotation), new { AnnotId = a.Annotationid }) }).ToList(); newMarkingModel.PostTitle = _repository.GetPostById(markedPost.PostId).Title; newMarkingModel.MarkedDate = markedPost.MarkingDate; newMarkingModel.AddAnnotation = Url.Link(nameof(AnnotationController.AddAnnotation), new { Pid = markedPost.MarkedPostId, text = "NewAnnotation", from = 0, to = 0 }); return(Ok(newMarkingModel)); }
public IActionResult AddMarkingWithAnnotation(int Pid, string annotation) { _repository.AddMarkingWithAnnotation(Pid, annotation, 0, 0); var markedPost = _repository.GetMarkingById(Pid); var newMarkingModel = new MarkingModel(); newMarkingModel.PostId = Pid; // Checking whether the post is an answer or question to give it the correct link newMarkingModel.MarkingUrl = Url.Link(nameof(GetMarking), new { Pid = markedPost.MarkedPostId }); newMarkingModel.PostUrl = _repository.GetPostById(markedPost.MarkedPostId).PostTypeId == 2 ? Url.Link(nameof(AnswerController.GetAnswerById), new { Qid = _repository.GetPostById(markedPost.MarkedPostId).ParentId, Aid = markedPost.MarkedPostId }) : Url.Link(nameof(QuestionController.GetQuestionById), new { Qid = markedPost.MarkedPostId }); newMarkingModel.MarkingAnnotation = _repository.GetAnnotationsByMarkingId(markedPost.MarkedPostId).ToList().Select(a => new AnnotationModel { MarkingLink = Url.Link(nameof(GetMarking), new { Qid = a.MarkedPostId }), AnnotationText = a.Annotation, From = a.From, To = a.To, EditAnnotation = Url.Link(nameof(AnnotationController.EditAnnotation), new { AnnotId = a.Annotationid, text = "SampleText" }), RemoveAnnotation = Url.Link(nameof(AnnotationController.EditAnnotation), new { Pid = a.MarkedPostId }) }).ToList(); newMarkingModel.MarkedDate = markedPost.MarkingDate; newMarkingModel.AddAnnotation = Url.Link(nameof(AnnotationController.AddAnnotation), new { Pid = markedPost.MarkedPostId, text = "New_Annotation", from = 0, to = 0 }); return(Created($"api/marking/{Pid}/{annotation}", newMarkingModel)); }
public IActionResult Put(int id, [FromBody] MarkingModel model) { var marking = ModelFactory.MapMarking(model); marking.PostId = id; if (!DataService.UpdateMarking(marking)) { return(NotFound()); } return(Ok()); }