예제 #1
0
        public HttpResponse Index()
        {
            if (this.IsUserLoggedIn())
            {
                var allProblems = this.problemsService.GetAllProblems();

                var model = new IndexLoggedInViewModel()
                {
                    Problems = allProblems
                };

                return(this.View(model, "IndexLoggedIn"));
            }

            return(this.View());
        }
예제 #2
0
        public async Task <IActionResult> IndexLoggedIn()
        {
            var userId = this.userManager.GetUserId(this.User);

            var userViewModel          = this.usersService.GetUserCompanyName(userId);
            var indexLoggedInViewModel = new IndexLoggedInViewModel
            {
                CurrentUser  = userViewModel,
                Reservations = await this.reservationService.GetAllReservationsByUserIdAsync(userId),
            };

            if (indexLoggedInViewModel.Reservations.Count() == 0)
            {
                return(this.View("NoResult", indexLoggedInViewModel));
            }
            else
            {
                return(this.View(indexLoggedInViewModel));
            }
        }
예제 #3
0
        public IHttpResponse Index()
        {
            var user = this.db.Users.FirstOrDefault(u => u.Username == this.User.Username);

            if (user != null)
            {
                var yourChannels = this.db.Channels.Where(ch => ch.Followers
                                                          .Any(u => u.User.Username == this.User.Username))
                                   .Select(vm => new FollowedChannelViewModel
                {
                    Id        = vm.Id,
                    Name      = vm.Name,
                    Type      = vm.Type,
                    Followers = vm.Followers.Count
                })
                                   .ToList();

                var followedChannelsTags = this.db.Channels.Where(ch => ch.Followers
                                                                  .Any(u => u.User.Username == this.User.Username))
                                           .SelectMany(ch => ch.Tags
                                                       .Select(t => t.Tag.Id))
                                           .ToList();

                var suggestedChannels = this.db.Channels.Where(ch => !ch.Followers
                                                               .Any(u => u.User.Username == this.User.Username) &&
                                                               ch.Tags.Any(t => followedChannelsTags
                                                                           .Contains(t.TagId)))
                                        .Select(vm => new FollowedChannelViewModel
                {
                    Id        = vm.Id,
                    Name      = vm.Name,
                    Type      = vm.Type,
                    Followers = vm.Followers.Count
                })
                                        .ToList();

                var ids = yourChannels.Select(x => x.Id).ToList();
                ids = ids.Concat(suggestedChannels.Select(x => x.Id)).ToList();
                ids = ids.Distinct().ToList();

                var seeOthers = this.db.Channels.Where(ch => !ids.Contains(ch.Id))
                                .Select(vm => new FollowedChannelViewModel
                {
                    Id        = vm.Id,
                    Name      = vm.Name,
                    Type      = vm.Type,
                    Followers = vm.Followers.Count
                })
                                .ToList();

                var loggedInViewModel = new IndexLoggedInViewModel
                {
                    YourChannels = yourChannels,
                    Suggested    = suggestedChannels,
                    SeeOther     = seeOthers
                };

                return(this.View("Home/IndexLoggedIn", loggedInViewModel));
            }

            return(this.View());
        }