Exemplo n.º 1
0
        private async Task <RouteDetailViewModel> GetDetailViewModel(int id)
        {
            List <CommentViewModel> comments = new List <CommentViewModel>();

            Route route = _routeService.GetRouteWithDifficultyById(id);

            List <RouteSection> sections = _routeService.GetRouteSectionsThatRouteIsIn(id);
            RouteHall           hall     = _routeService.GetRouteHallById(sections.First().RouteHallID);

            List <ApplicationUser> creators = _routeService.GetRouteCreators(id);

            bool creatorOrAdmin = false;

            ApplicationUser user        = null; // TODO: This makes no sense
            bool            userIsAdmin = false;

            if (_userService.IsSignedIn(User))
            {
                user = await _userService.GetUserAsync(User);

                userIsAdmin = await _userService.IsInRoleAsync(user, RoleHandler.Admin);

                creatorOrAdmin = creators.Contains(user) || (await _userService.IsInRoleAsync(user, RoleHandler.Admin));
            }

            List <Comment> allCommentsInRoute = _routeService.GetCommentsInRoute(id);
            List <Comment> topLevelComments   = allCommentsInRoute
                                                .Where(x => x.OriginalPostID == 0)
                                                .ToList();

            foreach (Comment comment in topLevelComments)
            {
                comments.Add(FetchCommentData(comment, allCommentsInRoute, user, userIsAdmin));
            }
            comments = comments.OrderByDescending <CommentViewModel, DateTime>(c => c.Date).ToList();

            // Get all the images related to the route
            string[] imagePaths = _routeService.GetAllImagePathsInRoute(id);

            // Get the video url from the route attachment
            string url = _routeService.GetVideoUrlInRoute(id);

            RouteDetailViewModel model = new RouteDetailViewModel
            {
                Route          = route,
                Sections       = sections,
                Hall           = hall,
                Creators       = creators,
                EditRights     = creatorOrAdmin,
                Comments       = comments,
                Images         = imagePaths,
                VideoUrl       = url,
                UserIsLoggedIn = _userService.IsSignedIn(User) // TODO: This makes no sense
            };

            return(model);
        }
Exemplo n.º 2
0
        public void AddHall(string name, RouteType type)
        {
            type--;
            RouteHall hall = new RouteHall
            {
                Name     = name,
                Sections = new List <RouteSection>()
            };

            if (type >= 0)
            {
                hall.ExpectedType = type;
            }

            _dbContext.RouteHalls.Add(hall);
            _dbContext.SaveChanges();
        }