public IActionResult GetReplies(int ideationId, [FromQuery(Name = "sortBy")] string sortBy = "recent") { List <IdeationReply> replies = _ideationManager.GetIdeationReplies(ideationId, 0, 999, sortBy).ToList(); if (!replies.Any()) { return(Ok()); } var replyDtos = new List <IdeationReplyDTO>(); replies.ForEach(r => { var replyDto = new IdeationReplyDTO() { IdeationReplyId = r.IdeationReplyId, IdeationId = r.Ideation.IdeationId, UpVotes = r.Upvotes, NumberOfComments = _ideationManager.CommentAmount(r.IdeationReplyId), CreatedString = r.Created.FormatParasableDate(), Title = r.Title, UserDisplayName = r.User.GetDisplayName() }; replyDtos.Add(replyDto); }); return(Ok(replyDtos)); }
public IActionResult GetReplies(int ideationId, int skip, int take, [FromQuery(Name = "sortBy")] string sortBy = "recent") { List <IdeationReply> replies; int replyAmount; if (sortBy == "reported") { replies = _ideationManager.GetReportedIdeationReplies(ideationId, skip, take).ToList(); replyAmount = _ideationManager.GetReportedIdeationReplyCountByIdeation(ideationId); } else { replies = _ideationManager.GetIdeationReplies(ideationId, skip, take, sortBy).ToList(); replyAmount = _ideationManager.GetIdeationReplyCountByIdeation(ideationId); } if (!replies.Any()) { return(Ok()); } var replyDtos = new List <IdeationReplyDTO>(); replies.ForEach(r => { var replyDto = new IdeationReplyDTO() { IdeationReplyId = r.IdeationReplyId, IdeationId = r.Ideation.IdeationId, UpVotes = r.Upvotes, NumberOfComments = _ideationManager.CommentAmount(r.IdeationReplyId), CreatedString = r.Created.FormatParasableDate(), Title = r.Title, UserDisplayName = r.User.GetDisplayName() }; if (sortBy == "reported") { replyDto.UserDisplayName = r.User.GetFullName(); replyDto.ReportCount = r.Reports.Count; } replyDtos.Add(replyDto); }); return(Ok(new { count = replyAmount, replies = replyDtos })); }
public IActionResult PostIdeationReply([FromForm] IdeationReplyDTO ideationReplyDto) { // return Created("/ideation/overview/1", null); //log test 1 Ideation ideation = _ideationManager.GetIdeationWithQuestions(ideationReplyDto.IdeationId); //log test 2 User user = _usermanager.GetUserAsync(User).Result; //log test 3 if (ideation == null || user == null) { return(NotFound()); } //log test 4 IdeationReply newReply = new IdeationReply() { Ideation = ideation, Title = ideationReplyDto.Title, Answers = new List <Answer>(), Votes = new List <Vote>(), Comments = new List <Comment>(), Created = DateTime.Now, User = user, Reports = new List <IdeationReport>() }; //log test 5 int index = 0; ideationReplyDto.Answers.ForEach(dto => { Answer newAnswer = null; switch (dto.FieldType) { case FieldType.OpenText: newAnswer = new OpenTextAnswer() { QuestionIndex = dto.QuestionIndex, Value = dto.OpenAnswer }; break; case FieldType.Image: case FieldType.Video: string fileName = Util.Util.GenerateDataStoreObjectName(dto.FileAnswer.FileName); string pathName = _fileUploader.UploadFile(fileName, "ideationReply", dto.FileAnswer).Result; newAnswer = new MediaAnswer() { QuestionIndex = dto.QuestionIndex, Value = new Media() { Name = dto.FileAnswer.FileName, Url = pathName } }; break; case FieldType.SingleChoice: case FieldType.DropDown: newAnswer = new SingleChoiceAnswer() { QuestionIndex = dto.QuestionIndex, SelectedChoice = dto.SingleAnswer }; break; case FieldType.MultipleChoice: newAnswer = new MultipleChoiceAnswer() { QuestionIndex = dto.QuestionIndex, SelectedChoices = dto.MultipleAnswer }; break; case FieldType.Location: newAnswer = new LocationAnswer() { QuestionIndex = dto.QuestionIndex, Value = new Location() { Latitude = dto.LocationAnswer.Latitude, Longitude = dto.LocationAnswer.Longitude, ZoomLevel = dto.LocationAnswer.ZoomLevel, } }; break; default: throw new ArgumentOutOfRangeException(); } newAnswer.OrderIndex = index++; newReply.Answers.Add(newAnswer); }); //log test 6 _ideationManager.AddIdeationReply(newReply); //log test 7 // Create activity var activity = CreateActivity(ActivityType.IdeationReply, user); activity.IdeationReply = newReply; _activityManager.AddActivity(activity); //log test 8 // Save everything _unitOfWorkManager.Save(); //log test 9 // Push activity var activityVm = new ActivityViewModel(activity); //log test 10 PushWebsockets(activityVm).Wait(); //log test 11 return(Created("/ideation/view/" + newReply.IdeationReplyId, new { id = newReply.IdeationReplyId })); }