Пример #1
0
        public MktApplication SaveAppBeforeSubmitToCreditChecking(MktApplication app, UserProfile userProfile)
        {
            using (var transaction = _appRepo.BeginTransaction())
            {
                _appRepo.Commit();

                _appRepo.UpdateApplicationCurrentCarId(app.Car.Id, app.AppId, transaction);

                // FastTrack เป็น 0 เพราะยังไม่ได้เลือก [อาชีพ]
                _appRepo.UpdateFastTrack(app.AppId, transaction);

                transaction.Commit();
            }

            return(app);
        }
Пример #2
0
        public IHttpActionResult CreateCar([FromBody] CarForCreationDto carFromBody, int userId)
        {
            try
            {
                if (carFromBody == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                if (!_userRepository.UserExists(userId))
                {
                    return(NotFound());
                }

                var car = Mapper.Map <Car>(carFromBody);


                _carRepository.AddCarForUser(userId, car);


                if (!_appRepository.Commit())
                {
                    return(InternalServerError());
                }

                var carToReturn = Mapper.Map <CarDto>(car);

                return(CreatedAtRoute("GetCar", new { id = carToReturn.Id }, carToReturn));
            }
            catch (Exception e)
            {
                return(InternalServerError());
            }
        }
Пример #3
0
        public IHttpActionResult CreateJourney([FromBody] JourneyForCreationDto JourneyFromBody, int userId, int carId)
        {
            try
            {
                if (JourneyFromBody == null)
                {
                    return(BadRequest());
                }

                var car = _carRepository.GetCarForUser(userId, carId, false);

                if (car == null)
                {
                    return(NotFound());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var routes = Mapper.Map <IEnumerable <PassengerRoute> >(JourneyFromBody.Routes);

                if (!_passengerRouteRepository.UsersExistForRoutes(routes))
                {
                    return(BadRequest());
                }

                if (_passengerRouteService.SameUserForRoutes(routes))
                {
                    return(BadRequest());
                }

                _passengerRouteRepository.SetUsersForRoutes(routes);

                var journey = Mapper.Map <Journey>(JourneyFromBody);

                journey.PassengerRoutes.AddRange(routes);

                _journeyService.GiveTotalPrices(journey, (double)JourneyFromBody.PriceForLiter, car.FuelConsumption100km);

                var payments = _paymentService.GeneratePayments(journey, userId);

                _userService.EditUsersPaymentStatistics(payments, userId);

                //notification service albo repozytorium wysle notyfikacje

                _journeyRepository.AddJourneyForUserAndCar(userId, carId, journey);

                _paymentRepository.AddPayments(payments);

                if (!_appRepository.Commit())
                {
                    return(InternalServerError());
                }

                var journeyToReturn = Mapper.Map <JourneyDto>(journey);

                return(CreatedAtRoute("GetJourneyForUserAndCar", new { userId = userId, id = journey.Id, passengerRoutes = true, carId = carId }, journeyToReturn));
            }
            catch (Exception e)
            {
                return(InternalServerError());
            }
        }