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

            var tripFromDb = this.tripService.GetTripById(tripId);

            if (tripFromDb == null)
            {
                return(this.Redirect("/Trips/All"));
            }

            var tripDetailsViewModel = new TripDetailsViewModel
            {
                Id            = tripFromDb.Id,
                StartPoint    = tripFromDb.StartPoint,
                EndPoint      = tripFromDb.EndPoint,
                DepartureTime = tripFromDb.DepartureTime.ToString("dd.MM.yyyy HH:mm"),
                Seats         = tripFromDb.Seats,
                Description   = tripFromDb.Description,
                ImagePath     = tripFromDb.ImagePath
            };

            return(this.View(tripDetailsViewModel));
        }
예제 #2
0
        public void AddCreatedViewModelsToListAdneReturnIt()
        {
            var vm = new TripDetailsViewModel();

            creatorMock = new Mock <ITripDetailsCreator>();
            creatorMock.Setup(cm => cm.CreateViewModel(It.IsAny <TripDetails>()))
            .Returns(vm);

            InitializeFacMock();

            converter = new TripDetailsViewModelConverter(facMock.Object);

            var inputList = new List <TripDetails>
            {
                new TripDetails(),
                new TripDetails(),
                new TripDetails(),
                new TripDetails()
            };

            var @out = converter.Convert(
                inputList,
                ViewerType.Driver
                );

            foreach (var item in @out)
            {
                Assert.Equal(vm, item);
            }
        }
예제 #3
0
        public HttpResponse Details(string tripId)
        {
            var trip = this.data.Trips.FirstOrDefault(t => t.Id == tripId);

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

            int availableSeats = trip.Seats - goingUsers.Count();

            var tripDetails = new TripDetailsViewModel
            {
                Id            = trip.Id,
                StartPoint    = trip.StartPoint,
                EndPoint      = trip.EndPoint,
                DepartureTime = trip.DepartureTime.ToLocalTime(),
                Description   = trip.Description,
                Seats         = availableSeats,
                ImagePath     = trip.ImagePath
            };

            return(View(tripDetails));
        }
        public HttpResponse Details(string tripId)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            TripDetailsViewModel tripDetailsViewModel = this.tripsService.Details(tripId);

            return(this.View(tripDetailsViewModel));
        }
예제 #5
0
        public ActionResult EditTrip(TripDetailsViewModel trip)
        {
            var tripToUpdate = this.trips.GetByIntId(trip.Id);
            var from = this.locations.GetAll().FirstOrDefault(x => x.Name == trip.From);
            var to = this.locations.GetAll().FirstOrDefault(x => x.Name == trip.To);
            tripToUpdate.FromId = from.Id;
            tripToUpdate.ToId = to.Id;
            tripToUpdate.AvailableSeats = trip.AvailableSeats;
            tripToUpdate.Description = trip.Description;
            tripToUpdate.StartDate = trip.StartDate;
            this.trips.Update(tripToUpdate);

            return this.RedirectToAction("Index", "MyTrips");
        }
예제 #6
0
        public IHttpActionResult GetTripDetailsById(int id)
        {
            var trip = _tripRepository.GetById(id);
            var user = _userRepository.FindById(trip.Driver.Id);

            var result = new TripDetailsViewModel()
            {
                Trip          = trip,
                DriverName    = user.UserName,
                DriverProfile = user.Profile
            };

            return(Ok(result));
        }
예제 #7
0
        public void SetIsUserPassangerToTrue_IfUSerIsPassanger()
        {
            // Arrange
            var mockedTripService     = new Mock <ITripService>();
            var mockedTagService      = new Mock <ITagService>();
            var mockedCarService      = new Mock <ICarService>();
            var mockedMappingProvider = new Mock <IMappingProvider>();

            var controller = new TripController(
                mockedTripService.Object,
                mockedTagService.Object,
                mockedCarService.Object,
                mockedMappingProvider.Object);

            int tripId       = 1;
            var driverId     = "UserId";
            var loggedUserId = "loggedUserId";
            var tripDetails  = new TripDetails()
            {
                Id = tripId
            };

            mockedTripService.Setup(x => x.GetTripDetails(tripId))
            .Returns(tripDetails);

            var tripDetailsViewModel = new TripDetailsViewModel();

            tripDetailsViewModel.Driver = new UserBannerViewModel()
            {
                Id = driverId
            };
            mockedMappingProvider.Setup(x => x.Map <TripDetails, TripDetailsViewModel>(tripDetails))
            .Returns(tripDetailsViewModel);

            controller.GetLoggedUserId = () => loggedUserId;

            mockedTripService.Setup(x => x.IsPassengerInTrip(loggedUserId, tripId))
            .Returns(true);

            // Act and Assert
            controller.WithCallTo(x => x.TripDetails(tripId))
            .ShouldRenderDefaultView()
            .WithModel(tripDetailsViewModel);

            Assert.IsFalse(tripDetailsViewModel.IsCurrentUserOwner);
            Assert.IsTrue(tripDetailsViewModel.IsCurrentUserPassangerInTheTrip);
        }
예제 #8
0
        public IActionResult Details(string tripId)
        {
            var trip = this.tripService.GetTripById(tripId);

            var model = new TripDetailsViewModel
            {
                Id            = trip.Id,
                StartPoint    = trip.StartPoint,
                Seats         = trip.Seats,
                DepartureTime = trip.DepartureTime.ToString("dd.MM.yyyy HH:mm"),
                Description   = trip.Description,
                EndPoint      = trip.EndPoint,
                Image         = trip.ImagePath,
            };

            return(this.View(model));
        }
예제 #9
0
        public TripDetailsViewModel GetById(string tripId)
        {
            var trip = this.db.Trips.FirstOrDefault(t => t.Id == tripId);

            var tripDetailsViewModel = new TripDetailsViewModel()
            {
                Id            = trip.Id,
                Description   = trip.Description,
                StartPoint    = trip.StartPoint,
                EndPoint      = trip.EndPoint,
                ImagePath     = trip.ImagePath,
                DepartureTime = trip.DepartureTime.ToString("dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture),
                Seats         = trip.Seats
            };

            ;
            return(tripDetailsViewModel);
        }
예제 #10
0
        public TripDetailsViewModel CreateViewModel(TripDetails tripDetails)
        {
            var ret = new TripDetailsViewModel
            {
                TripId             = tripDetails.Id,
                Size               = tripDetails.Size,
                Cost               = tripDetails.Cost,
                Description        = tripDetails.Description,
                VechicleModel      = tripDetails.VechicleModel,
                Date               = tripDetails.Date,
                DateEnd            = tripDetails.DateEnd,
                IsSmokingAllowed   = tripDetails.IsSmokingAllowed,
                DestinationAddress = tripDetails.DestinationAddress,
                StartingAddress    = tripDetails.StartingAddress,
                DriverId           = tripDetails.DriverId,
                DriverUsername     = repository.GetById(tripDetails.DriverId).UserName
            };

            return(ret);
        }
예제 #11
0
        public ActionResult TripDetails(int id)
        {
            TripDetails          tripDetails     = this.tripService.GetTripDetails(id);
            TripDetailsViewModel tripDetailsView = this.mappingProvider.Map <TripDetails, TripDetailsViewModel>(tripDetails);

            var loggedUserId = base.GetLoggedUserId();

            bool isUserAlreadyAppliedToTrip = false;
            bool isUserOwner =
                loggedUserId == tripDetailsView.Driver.Id;

            if (loggedUserId != null)
            {
                isUserAlreadyAppliedToTrip = this.tripService.IsPassengerInTrip(loggedUserId, id);
            }

            tripDetailsView.IsCurrentUserPassangerInTheTrip = isUserAlreadyAppliedToTrip;
            tripDetailsView.IsCurrentUserOwner = isUserOwner;

            return(View(tripDetailsView));
        }
예제 #12
0
        public HttpResponse Details(string tripId)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var targetTrip = this.tripService.GetDetails(tripId);
            var viewModel  = new TripDetailsViewModel
            {
                Id            = targetTrip.Id,
                ImagePath     = targetTrip.ImagePath,
                StartPoint    = targetTrip.StartPoint,
                EndPoint      = targetTrip.EndPoint,
                DepartureTime = targetTrip.DepartureTime.ToString("yyyy-MM-dd HH:mm").Replace(" ", "T"),
                Description   = targetTrip.Description,
                Seats         = tripService.GetTripFreePlaces(targetTrip)
            };

            return(this.View(viewModel));
        }
예제 #13
0
        public HttpResponse Details(string tripId)
        {
            if (!IsUserLoggedIn())
            {
                return(Redirect("/Home/Index"));
            }

            var tripServiceModel = tripService.GetById(tripId);

            var trip = new TripDetailsViewModel
            {
                Id            = tripServiceModel.Id,
                Seats         = tripServiceModel.Seats,
                StartPoint    = tripServiceModel.StartPoint,
                EndPoint      = tripServiceModel.EndPoint,
                Description   = tripServiceModel.Description,
                ImagePath     = tripServiceModel.ImagePath,
                DepartureTime = tripServiceModel.DepartureTime.ToString("dd.MM.yyyy HH:mm")
            };

            return(this.View(trip));
        }
        public TripDetailsViewModel GetTrip(string id)
        {
            var trip = this.db.Trips.Where(x => x.Id == id).FirstOrDefault();

            if (trip == null)
            {
                return(null);
            }

            var model = new TripDetailsViewModel()
            {
                Id            = trip.Id,
                StartPoint    = trip.StartPoint,
                EndPoint      = trip.EndPoint,
                DepartureTime = trip.DepartureTime.ToString("dd.MM.yyyy HH: mm"),
                ImagePath     = trip.ImagePath,
                Seats         = trip.Seats - 2,
                Description   = trip.Description
            };

            return(model);
        }
        public HttpResponse Details(string tripId)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            var trip = this.service.GetTrip(tripId);

            var model = new TripDetailsViewModel
            {
                DepartureTime = trip.DepartureTime.ToString("dd.MM.yyyy HH:mm"),
                Description   = trip.Description,
                EndPoint      = trip.EndPoint,
                Id            = trip.Id,
                ImagePath     = trip.ImagePath,
                Seats         = trip.Seats,
                StartPoint    = trip.StartPoint
            };

            return(this.View(model));
        }
예제 #16
0
        public async Task <IActionResult> Details(int id)
        {
            var model = new TripDetailsViewModel()
            {
                Trip       = await this.trips.DetailsByIdAsync(id),
                Passangers = await this.trips.PassangersInTripAsync(id)
            };

            if (model.Trip == null)
            {
                return(this.NotFound());
            }

            if (this.User.Identity.IsAuthenticated)
            {
                var userId = this.userManager.GetUserId(this.User);

                model.UserIsSignedInCourse =
                    await this.trips.UserIsSignedForTripAsync(userId, id);
            }

            return(this.View(model));
        }
예제 #17
0
        public HttpResponse Details(string tripId)
        {
            var trip = this.data.Trips
                       .Include(t => t.UserTrips)
                       .FirstOrDefault(t => t.Id == tripId);

            if (trip == null)
            {
                return(Error($"Trip does not exist. ID: '{tripId}'"));
            }

            var tripViewModel = new TripDetailsViewModel
            {
                Id            = trip.Id,
                StartPoint    = trip.StartPoint,
                EndPoint      = trip.EndPoint,
                DepartureTime = trip.DepartureTime.ToString("dd.MM.yyyy HH:mm"),
                Seats         = trip.Seats - trip.UserTrips.Count,
                Description   = trip.Description,
                ImagePath     = trip.ImagePath
            };

            return(View(tripViewModel));
        }
예제 #18
0
        public Response Details(string tripId)
        {
            TripDetailsViewModel model = tripService.GetTripDetails(tripId);

            return(View(model));
        }
        // GET: Trips/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            var loggedInMember = await _memberService.GetLoggedInMemberAsync();

            PlaceLoggedInNameInViewData(loggedInMember);

            Trip trip;

            // Set the error message, ready if something goes wrong.
            ViewData["ErrorMessage"] = "An error ocurred trying to get the trip details. Please try again.";
            if (id == null)
            {
                return(View(appErrorPath));
            }
            int tripID = id ?? 0;

            try
            {
                trip = await _tripService.GetTripDetailsAsync(tripID);

                if (trip == null)
                {
                    return(View(appErrorPath));
                }
            }
            catch
            {
                return(View(appErrorPath));
            }
            // Clear error message
            ViewData["ErrorMessage"] = "";

            //Get leader and list of participants from the trip signups.
            //Also determine if logged in member is a leader or participant (or neither).
            string        leaderName                  = "Not Found";
            bool          loggedInMemberIsLeader      = false;
            bool          loggedInMemberIsParticipant = false;
            List <string> participantNames            = new List <string>();

            foreach (var signup in trip.Signups)
            {
                if (signup.AsLeader)
                {
                    leaderName = signup.Member.Name;
                    if (loggedInMember.MemberID == signup.MemberID)
                    {
                        loggedInMemberIsLeader = true;
                    }
                }
                else
                {
                    participantNames.Add(signup.Member.Name);
                    if (loggedInMember.MemberID == signup.MemberID)
                    {
                        loggedInMemberIsParticipant = true;
                    }
                }
            }

            //Determine which actions will be available.
            bool tripIsFull      = (participantNames.Count + 1 >= trip.MaxParticipants);
            bool includeDelete   = false;
            bool includeEdit     = false;
            bool includeWithdraw = false;
            bool includeSignup   = false;

            if (loggedInMemberIsLeader)
            {
                includeDelete = true;
                includeEdit   = true;
            }
            else if (loggedInMemberIsParticipant)
            {
                includeWithdraw = true;
            }
            else if (!tripIsFull)
            {
                includeSignup = true;
            }

            //Prepare view
            var tripDetailsView = new TripDetailsViewModel
            {
                Trip             = trip,
                LeaderName       = leaderName,
                ParticipantNames = participantNames,
                MemberName       = loggedInMember.Name,
                IncludeDelete    = includeDelete,
                IncludeEdit      = includeEdit,
                IncludeWithdraw  = includeWithdraw,
                IncludeSignup    = includeSignup
            };

            return(View(tripDetailsView));
        }