Example #1
0
        public IActionResult GetAllStatementForms(int id, [FromServices] IIoTManager ioTManager)
        {
            List <Form> forms = _formManager.GetAllStatementForms(id).ToList();

            List <FormViewModel> formViewModels = new List <FormViewModel>();

            foreach (Form form in forms)
            {
                IotLink       iotLink       = ioTManager.GetIoTLinkByForm(form);
                FormViewModel formViewModel = new FormViewModel()
                {
                    Title     = form.Title,
                    FormId    = form.FormId,
                    Questions = new List <FormQuestionViewModel>(),
                    IotLink   = iotLink
                };

                FormQuestionViewModel question = new FormQuestionViewModel()
                {
                    Question = form.Questions[0].QuestionString
                };

                formViewModel.Questions.Add(question);
                formViewModels.Add(formViewModel);
            }

            return(Ok(formViewModels));
        }
Example #2
0
        public IActionResult Details(int id, [FromServices] IIoTManager ioTManager)
        {
            var tenant  = Util.GetSubdomain(HttpContext.Request.Host.ToString());
            var project = _projectManager.GetProject(id);

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

            var subdomain        = Util.GetSubdomain(HttpContext.Request.Host.ToString());
            var projectSubdomain = project.Platform.Tenant;

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

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

            if (user != null)
            {
                ViewBag.IsAdmin = _userManager.IsUserAdminOrAbove(user, tenant);
            }
            else
            {
                ViewBag.IsAdmin = false;
            }

            ViewBag.IoTCount = ioTManager.GetIotCountByProject(project.ProjectId);

            return(View(project));
        }
Example #3
0
        //TODO usermanger meegeven in index of in constructor?! Refactor Jeroen please, vraag aan Sam voor refactor
        public IActionResult Index(string tenant, [FromServices] IIdeationManager ideationManager,
                                   [FromServices] UserManager <User> userManager, [FromServices] IIoTManager ioTManager)
        {
            var platform = _platformManager.GetPlatformByTenant(tenant);

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

            var activities         = _activityManager.GetActivityFeed(platform);
            var activityViewModels = new List <ActivityViewModel>();

            foreach (var activity in activities.Reverse())
            {
                var vm = new ActivityViewModel(activity);
                activityViewModels.Add(vm);
            }

            ViewBag.Activities         = activityViewModels;
            ViewBag.IdeationReplyCount = ideationManager.GetIdeationReplyCount(platform.PlatformId);
            ViewBag.CommentCount       = ideationManager.GetCommentCount(platform.PlatformId);
            ViewBag.VoteCount          = ideationManager.GetTotalVoteCount(platform.PlatformId);
            ViewBag.IoTCount           = ioTManager.GetIotCountByPlatform(platform.PlatformId);

            ViewBag.ProjectVoteCount          = new List <int>();
            ViewBag.ProjectCommentCount       = new List <int>();
            ViewBag.ProjectIdeationReplyCount = new List <int>();

            var users = userManager.Users;
            var count = 0;

            foreach (var userCount in users)
            {
                if (userManager.GetClaimsAsync(userCount).Result.SingleOrDefault(c => c.Type == _subdomain) != null)
                {
                    count++;
                }
            }
            ViewBag.UserCount = count;

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

            if (user != null)
            {
                ViewBag.IsAdmin = userManager.IsUserAdminOrAbove(user, tenant);
            }
            else
            {
                ViewBag.IsAdmin = false;
            }

            return(View(platform));
        }
Example #4
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));
        }
Example #5
0
 public VoteController(
     IIoTManager ioTManager,
     IIdeationManager ideationManager,
     IFormManager formManager,
     IPlatformManager platformManager,
     IActivityManager activityManager,
     UnitOfWorkManager unitOfWorkManager
     )
 {
     _ioTManager        = ioTManager;
     _ideationManager   = ideationManager;
     _formManager       = formManager;
     _platformManager   = platformManager;
     _activityManager   = activityManager;
     _unitOfWorkManager = unitOfWorkManager;
 }
Example #6
0
        public IActionResult GetIoTLinksByPlatform(int platformId, [FromServices] IIoTManager ioTManager)
        {
            List <IotLink> iotLinks = ioTManager.GetIotLinksByPlatform(platformId).ToList();
            List <IoTDTO>  iots     = new List <IoTDTO>();

            foreach (var iotLink in iotLinks)
            {
                IoTDTO ioT = new IoTDTO()
                {
                    Location = new LocationDTO()
                    {
                        Latitude  = iotLink.Location.Latitude,
                        Longitude = iotLink.Location.Longitude,
                        ZoomLevel = iotLink.Location.ZoomLevel
                    },
                    IsForm = iotLink.Form != null,
                };
                if (iotLink.Form != null)
                {
                    ioT.Question = iotLink.Form.Questions[0].QuestionString;
                    int upvotes   = iotLink.Form.Replies.Select(f => ((SingleChoiceAnswer)f.Answers[0]).SelectedChoice).Count(c => c == 1);
                    int downvotes = iotLink.Form.Replies.Select(f => ((SingleChoiceAnswer)f.Answers[0]).SelectedChoice).Count(c => c == 0);
                    ioT.UpVotes   = upvotes;
                    ioT.DownVotes = downvotes;
                    ioT.FormId    = iotLink.Form.FormId;
                }
                else
                {
                    ioT.Question   = iotLink.IdeationReply.Ideation.CentralQuestion;
                    ioT.UpVotes    = iotLink.IdeationReply.Upvotes;
                    ioT.DownVotes  = iotLink.IdeationReply.Downvotes;
                    ioT.IdeationId = iotLink.IdeationReply.IdeationReplyId;
                }

                iots.Add(ioT);
            }

            return(Ok(iots));
        }
Example #7
0
 public IActionResult RemoveLinkt(int id, [FromServices] IIoTManager ioTManager, [FromServices]  UnitOfWorkManager unitOfWorkManager)
 {
     ioTManager.DeleteLink(id);
     unitOfWorkManager.Save();
     return(Ok());
 }
Example #8
0
        public IActionResult EditLink(IoTDTO iot, [FromServices] IFormManager formManager, [FromServices] IIdeationManager ideationManager, [FromServices] IIoTManager ioTManager, [FromServices]  UnitOfWorkManager unitOfWorkManager)
        {
            IotLink link = ioTManager.GetIoTLink(iot.IotLinkId);

            Location location = new Location()
            {
                Longitude = iot.Location.Longitude,
                Latitude  = iot.Location.Latitude,
                ZoomLevel = iot.Location.ZoomLevel
            };

            link.Location = location;

            ioTManager.UpdateIotLink(link);
            unitOfWorkManager.Save();

            return(Ok());
        }
Example #9
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 }));
        }