Exemple #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 }));
        }
Exemple #2
0
        public IActionResult Reply(int id)
        {
            var      tenant   = Util.Util.GetSubdomain(HttpContext.Request.Host.ToString());
            Ideation ideation = _ideationManager.GetIdeationWithReplies(id);

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

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

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

            ViewBag.ProjectId = ideation.Project.ProjectId;

            if (ideation.IdeationType == IdeationType.Admin)
            {
                User user    = _userManager.GetUserAsync(User).Result;
                bool isAdmin = _userManager.IsUserAdminOrAbove(user, tenant);
                if (!isAdmin)
                {
                    return(Unauthorized());
                }
            }

            var ideationViewModel = new IdeationViewModel()
            {
                IdeationId      = ideation.IdeationId,
                CentralQuestion = ideation.CentralQuestion,
                Description     = ideation.Description,
                Url             = ideation.Url,
                UserId          = _userManager.GetUserAsync(User).Result.Id
            };

            return(View(ideationViewModel));
        }
        public IActionResult PostIdeationReplyApp([FromBody] IdeationReplyAppDto ideationReplyApp)
        {
            Ideation ideation = _ideationManager.GetIdeationWithReplies(ideationReplyApp.IdeationId);

            User user = _usermanager.FindByEmailAsync(HttpContext.User.Claims.FirstOrDefault(c => c.Type == "Email").Value).Result;

            IdeationReply newReply = new IdeationReply()
            {
                Ideation = ideation,
                Title    = ideationReplyApp.Title,
                Answers  = new List <Answer>(),
                Votes    = new List <Vote>(),
                Created  = DateTime.Now,
                Comments = new List <Comment>(),
                User     = user,
                Reports  = new List <IdeationReport>()
            };

            int index = 0;

            foreach (var dto in ideationReplyApp.Answers)
            {
                Answer newAnswer = null;

                switch (dto.FieldType)
                {
                case FieldType.OpenText:
                    newAnswer = new OpenTextAnswer()
                    {
                        QuestionIndex = dto.QuestionIndex,
                        Value         = dto.Reply
                    };
                    break;

                case FieldType.SingleChoice:
                case FieldType.DropDown:
                    newAnswer = new SingleChoiceAnswer()
                    {
                        QuestionIndex  = dto.QuestionIndex,
                        SelectedChoice = dto.SelectedChoice
                    };
                    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);
            }

            // Create activity
            var activity = CreateActivity(ActivityType.IdeationReply, user, ideation.Project.Platform);

            activity.IdeationReply = newReply;
            _activityManager.AddActivity(activity);

            // Save everything
            _unitOfWorkManager.Save();

            // Push activity
            var activityVm = new ActivityViewModel(activity);

            PushWebsockets(activityVm).Wait();

            return(Ok());
        }