Beispiel #1
0
        public void CancelReportIdeation(int id, User user)
        {
            IdeationReply  reply  = _ideationRepository.ReadIdeationReply(id);
            IdeationReport report = _ideationRepository.ReadIdeationReport(reply, user);

            _ideationRepository.DeleteIdeationReport(report);
        }
Beispiel #2
0
        public void ReportIdeation(int id, User user)
        {
            IdeationReply  reply  = _ideationRepository.ReadIdeationReply(id);
            IdeationReport report = new IdeationReport()
            {
                User             = user,
                ReportedIdeation = reply
            };

            _ideationRepository.CreateIdeationReport(report);
        }
Beispiel #3
0
 public void DeleteIdeationReport(IdeationReport report)
 {
     _ctx.Remove(report);
     _ctx.SaveChanges();
 }
Beispiel #4
0
 public void CreateIdeationReport(IdeationReport report)
 {
     _ctx.IdeationReports.Add(report);
     _ctx.SaveChanges();
 }
Beispiel #5
0
        public IActionResult View(int id)
        {
            var           tenant = Util.Util.GetSubdomain(HttpContext.Request.Host.ToString());
            IdeationReply reply  = _ideationManager.GetIdeationReply(id);

            if (reply == null)
            {
                return(RedirectToAction("NotFound", "Home"));
            }

            Ideation ideation = reply.Ideation;

            User user = _userManager.GetUserAsync(User).Result;

            if (ideation == null)
            {
                return(StatusCode(500));
            }

            var subdomain         = Util.Util.GetSubdomain(HttpContext.Request.Host.ToString());
            var ideationSubDomain = ideation.Project.Platform.Tenant;

            if (subdomain != ideationSubDomain)
            {
                return(RedirectToAction("NotFound", "Home"));
            }

            Vote vote = null;

            if (user != null)
            {
                vote = reply.Votes.Find(v => v.User == user);
            }

            ViewBag.IsAdminIdeation = ideation.IdeationType == IdeationType.Admin;
            ViewBag.ProjectId       = ideation.Project.ProjectId;
            ViewBag.IdeationId      = ideation.IdeationId;

            bool isMod = false;

            if (user != null)
            {
                isMod = _userManager.IsUserModOrAboveForProject(user, ideation.Project, tenant);
            }

            ViewBag.IsMod = isMod;
            IdeationReport report = reply.Reports.Find(r => r.User == user && r.ReportedIdeation == reply);

            ViewBag.HasReported = (report != null);

            var vm = new IdeationReplyViewModel()
            {
                IdeationReplyId = reply.IdeationReplyId,
                CentralQuestion = ideation.CentralQuestion,
                DateTime        = reply.Created,
                Title           = reply.Title,
                Answers         = new List <AnswerViewModel>(),
                UserDisplayName = reply.User.GetDisplayName(),
                UserHasVoted    = vote != null,
                UpVotes         = reply.Upvotes,
                DownVotes       = reply.Downvotes,
                IsFlagged       = reply.Reports.Any(),
                ReviewedByMod   = reply.ReviewedByMod,
                Hidden          = reply.Hidden
            };

            if (_userManager.IsUserAdminOrAbove(reply.User, tenant))
            {
                vm.UserDisplayName = reply.User.GetFullName();
            }

            if ((user != null && _userManager.IsUserModOrAbove(user, tenant)) || _userManager.IsUserOrganisation(reply.User))
            {
                //Mods can see the full name
                vm.UserDisplayName = reply.User.GetFullName();
            }

            foreach (Answer answer in reply.Answers)
            {
                Question        question = ideation.Questions.Find(q => q.OrderIndex == answer.QuestionIndex);
                AnswerViewModel answervm = new AnswerViewModel()
                {
                    FieldType      = question.FieldType,
                    QuestionString = question.QuestionString,
                };
                switch (question.FieldType)
                {
                case FieldType.OpenText:
                    answervm.OpenAnswer = (string)answer.GetValue();
                    break;

                case FieldType.Image:
                case FieldType.Video:
                    answervm.FileAnswer = (Media)answer.GetValue();
                    break;

                case FieldType.SingleChoice:
                case FieldType.DropDown:
                    int    singleAnswer         = (int)answer.GetValue();
                    string singleAnswerAsString = question.Options[singleAnswer];
                    answervm.SingleAnswer = singleAnswerAsString;
                    break;

                case FieldType.MultipleChoice:
                    List <bool>   multiAnswer          = (List <bool>)answer.GetValue();
                    List <string> multiAnswerAsStrings = new List <string>();
                    for (int i = 0; i < question.Options.Count; i++)
                    {
                        if (multiAnswer[i])
                        {
                            multiAnswerAsStrings.Add(question.Options[i]);
                        }
                    }

                    answervm.MultipleAnswer = multiAnswerAsStrings;
                    break;

                case FieldType.Location:
                    answervm.LocationAnswer = (Location)answer.GetValue();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                vm.Answers.Add(answervm);
            }

            return(View(vm));
        }