public HttpResponse All()
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var trips = this.tripsService
                        .GetAll(t => new TripsAllViewModel
            {
                Id            = t.Id,
                StartPoint    = t.StartPoint,
                EndPoint      = t.EndPoint,
                Seats         = t.Seats,
                DepartureTime = t.DepartureTime
                                .ToString("dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture)
            })
                        .ToList();

            var tripsListingViewModel = new TripsListingViewModel
            {
                Trips = trips
            };

            return(this.View(tripsListingViewModel));
        }
コード例 #2
0
        public HttpResponse All()
        {
            var tripsQuery = this.data
                             .Trips
                             .AsQueryable()
                             .ToList();

            var trips = new List <TripsListingViewModel>();

            foreach (var trip in tripsQuery)
            {
                var goingUsers = this.data
                                 .UsersTrips
                                 .Where(ut => ut.TripId == trip.Id)
                                 .Select(ut => ut.UserId)
                                 .ToList();

                var currentTrip = new TripsListingViewModel
                {
                    Id            = trip.Id,
                    StartPoint    = trip.StartPoint,
                    EndPoint      = trip.EndPoint,
                    DepartureTime = trip.DepartureTime.ToLocalTime(),
                    Seats         = trip.Seats - goingUsers.Count()
                };

                trips.Add(currentTrip);
            }

            //var trips = tripsQuery
            //    .Select(t => new TripsListingViewModel
            //    {
            //        Id = t.Id,
            //        StartPoint = t.StartPoint,
            //        EndPoint = t.EndPoint,
            //        DepartureTime = t.DepartureTime.ToLocalTime(),
            //        Seats = t.Seats
            //    })
            //    .ToList();

            return(View(trips));
        }