public IActionResult Add(JourneyViewModel model)
        {
            if (ModelState.IsValid)
            {
                model = _journeyService.AddJourney(model);

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
        public void TestJourneyAddsAndGetsAJourney()
        {
            var driver = new User()
            {
                Name = "Richard",
                From = "12345,54312"
            };

            var journey = new Journey()
            {
                Destination = "Hillington",
            };

            _journeyService.AddJourney(journey);

            var result = _journeyService.GetAllJourneys();

            Assert.Contains(journey, result.ToList());
        }
        public async Task <IActionResult> CreateJourney([FromBody] JourneyForCreationDto journeyFromBody, string userId, int carId)
        {
            var car = _carService.GetCar(userId, carId, true);

            if (car == null)
            {
                ModelState.AddModelError("", "Car with this id does not exist");
                return(BadRequest(ModelState));
            }

            var routes = journeyFromBody.Routes;

            if (!_passengerRouteService.RoutesUsersExist(routes))
            {
                ModelState.AddModelError("", "User from route does not exist");
                return(BadRequest(ModelState));
            }

            if (_passengerRouteService.SameUserForMultipleRoutes(routes))
            {
                ModelState.AddModelError("", "Multiple users for the same route");
                return(BadRequest(ModelState));
            }

            var journey = _journeyService.AddJourney(userId, journeyFromBody, car);

            _journeyService.SetTotalPrices(journey, car.FuelConsumption100km, journeyFromBody.PriceForLiter);

            var payments = _paymentService.AddPayments(journey);

            _userService.EditUsersPaymentStatistics(userId, payments);

            var journeyToReturn = _journeyService.GetJourney(journey);

            await _linksService.AddLinksAsync(journeyToReturn);

            return(CreatedAtRoute(Constants.RouteNames.GetJourneyByCar, new { userId = userId, id = journey.Id, carId = journey.CarId }, journeyToReturn));
        }
 public void Post([FromBody] Journey journey)
 {
     _journeyService.AddJourney(journey);
 }