Esempio n. 1
0
        public IActionResult CreateLink(IoTDTO iot, [FromServices] IFormManager formManager, [FromServices] IIdeationManager ideationManager, [FromServices] IIoTManager ioTManager, [FromServices]  UnitOfWorkManager unitOfWorkManager)
        {
            IotLink  link     = null;
            Location location = new Location()
            {
                Longitude = iot.Location.Longitude,
                Latitude  = iot.Location.Latitude,
                ZoomLevel = iot.Location.ZoomLevel
            };


            if (iot.IsForm)
            {
                Form form = formManager.GetForm(iot.FormId);
                if (form == null)
                {
                    return(NotFound());
                }
                link = ioTManager.CreateIotLink(form, null, form.Project, location);
            }

            else
            {
                Ideation      ideation = ideationManager.GetIdeationWithReplies(iot.IdeationId);
                IdeationReply reply    = ideationManager.GetIdeationReply(ideation.Replies[0].IdeationReplyId);
                if (reply == null)
                {
                    return(NotFound());
                }
                link = ioTManager.CreateIotLink(null, reply, ideation.Project, location);
            }
            unitOfWorkManager.Save();

            return(Created("", new { id = link.IotLinkId }));
        }
Esempio n. 2
0
        public IActionResult ViewIdeationReply(int id)
        {
            IdeationReply reply    = _ideationManager.GetIdeationReply(id);
            Ideation      ideation = reply.Ideation;

            if (reply == null)
            {
                return(NotFound());
            }

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

            var vm = new IdeationReplyViewModel()
            {
                IdeationReplyId = reply.IdeationReplyId,
                CentralQuestion = ideation.CentralQuestion,
                DateTime        = reply.Created,
                Answers         = new List <AnswerViewModel>(),
                UserDisplayName = reply.User.GetDisplayName(),
                UpVotes         = reply.Upvotes,
                Title           = reply.Title,
                DownVotes       = reply.Downvotes,
            };

            foreach (Answer answer in reply.Answers)
            {
                Question question = ideation.Questions.Find(q => q.OrderIndex == answer.QuestionIndex);
                if (question != null)
                {
                    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(Ok(vm));
        }
Esempio n. 3
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));
        }