예제 #1
0
        public IActionResult Overview(int id)
        {
            var tenant   = Util.Util.GetSubdomain(HttpContext.Request.Host.ToString());
            var 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"));
            }

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

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

            bool isMod = false;

            if (user != null)
            {
                isMod = _userManager.IsUserAdminOrAbove(user, tenant);

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

            ViewBag.IsMod = isMod;


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

            return(View(ideationViewModel));
        }
예제 #2
0
        public IActionResult GetAllAdminIdeations(int id, [FromServices] IIoTManager ioTManager)
        {
            List <Ideation> ideations = _ideationManager.GetAllAdminIdeations(id).ToList();

            List <IdeationViewModel> ideationViewModels = new List <IdeationViewModel>();


            foreach (var ideation in ideations)
            {
                bool hasReplies = ideation.Replies.Any();
                if (!hasReplies)
                {
                    continue;
                }
                IoTDTO iotLink = null;
                if (hasReplies)
                {
                    IotLink link = null;
                    link = ioTManager.GetIoTLinkByIdeationReply(ideation.Replies[0]);
                    if (link != null)
                    {
                        iotLink = new IoTDTO()
                        {
                            IotLinkId  = link.IotLinkId,
                            IsForm     = false,
                            IdeationId = ideation.Replies[0].IdeationReplyId,
                            Location   = new LocationDTO()
                            {
                                Longitude = link.Location.Longitude,
                                Latitude  = link.Location.Latitude,
                                ZoomLevel = link.Location.ZoomLevel
                            }
                        };
                    }
                }
                IdeationViewModel vm = new IdeationViewModel()
                {
                    CentralQuestion = ideation.CentralQuestion,
                    Description     = ideation.Description,
                    IdeationId      = ideation.IdeationId,
                    HasReplies      = hasReplies,
                    IotLink         = iotLink
                };
                ideationViewModels.Add(vm);
            }

            return(Ok(ideationViewModels));
        }