Exemplo n.º 1
0
 public bool AddPaymentRentInfo(PaymentRentInfo paymentRentInfo)
 {
     try
     {
         paymentRentInfo.Id = ObjectId.GenerateNewId().ToString();
         _context.PaymentRentInfo.InsertOne(paymentRentInfo);
         return(true);
     }
     catch (MongoWriteException)
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        public IHttpActionResult RentSuccess([FromBody] PaymentDetailsRequest paymentDetailsRequest)
        {
            Payment paymentHistory = _paymentService.GetPaymentByPaymentId(paymentDetailsRequest.PaymentId);

            if (paymentHistory == null || paymentHistory.state != AppConstants.CreatedState)
            {
                return(BadRequest());
            }

            PaymentRentInfo paymentDetails = _paymentService.GetPaymentRentInfoByPaymentId(paymentDetailsRequest.PaymentId);

            if (paymentDetails == null)
            {
                return(BadRequest());
            }

            Car car = _carService.GetCarById(paymentDetails.CarId);

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

            if (_carService.RentCar(car))
            {
                try
                {
                    car.RentedUntil = paymentDetails.RentedUntil;
                    _userService.AddUserRentalHistory(User.Identity.GetUserId(), car);
                    _paymentService.ExecutePayment(paymentDetailsRequest.PaymentId, paymentDetailsRequest.PayerId);
                    string carObject = JsonConvert.SerializeObject(car, new JsonSerializerSettings
                    {
                        ContractResolver = new CamelCasePropertyNamesContractResolver()
                    });
                    _carHub.Clients.All.carUpdated(carObject);

                    return(Ok());
                }
                catch (System.Exception)
                {
                    return(InternalServerError());
                }
            }

            return(BadRequest());
        }
Exemplo n.º 3
0
        public bool AddPaymentHistory(Payment payment, Car car, string userId)
        {
            ApplicationUser user = _userService.GetUserById(userId);

            if (user == null)
            {
                return(false);
            }

            PaymentRentInfo paymentRentInfo = new PaymentRentInfo
            {
                PaymentId   = payment.id,
                RentedUntil = car.RentedUntil.Value,
                UserId      = user.Id,
                CarId       = car.Id
            };

            return(_paymentHistoryRepository.AddPaymentRentInfo(paymentRentInfo));
        }