void populateDDLListOfParkingLots() { //List<Vehicle> lstVehicles = new List<Vehicle>(); ReservationTransaction transaction = new ReservationTransaction(); List <ParkingLot> lstParkingLots = transaction.ReadExistingParkingLots(); DropDownListParkingLots.DataTextField = "parkingLotName"; DropDownListParkingLots.DataValueField = "id"; DropDownListParkingLots.DataSource = lstParkingLots; DropDownListParkingLots.DataBind(); }
void populateDDLListOfVehicles(User user) { //List<Vehicle> lstVehicles = new List<Vehicle>(); ReservationTransaction transaction = new ReservationTransaction(); List <Vehicle> lstVehicles = transaction.ReadVehiclesOfUser(user); DropDownListVehiclesOfOneUser.DataTextField = "numberPlate"; DropDownListVehiclesOfOneUser.DataValueField = "id"; DropDownListVehiclesOfOneUser.DataSource = lstVehicles; DropDownListVehiclesOfOneUser.DataBind(); }
public void InsertReservationInGivenPeriod() { ReservationTransaction transaction = new ReservationTransaction(); int checkInTime = int.Parse(DropDownListCheckIn.SelectedItem.Value); int checkOutTime = int.Parse(DropDownListCheckOut.SelectedItem.Value); while (checkInTime <= checkOutTime) { SiCAP_GrupoCARARA.App_Domain.Reservation myReservation = FillReservation(checkInTime); transaction.InsertReservation(myReservation); checkInTime++; } }
public ReservationTransaction AddStripeChargeToPendingReservation(string currentUserId, string userIdFor, int reservationId, string tokenId, decimal amount) { var stripePaymentDetails = new TransactionStripeDetails { TokenId = tokenId }; var transactionPaymentDetails = new TransactionPaymentDetails { TransactionStripeDetails = stripePaymentDetails }; var resTransaction = new ReservationTransaction { TransactionPaymentDetails = transactionPaymentDetails, DateCreated = DateTime.UtcNow, DateCompleted = DateTime.UtcNow, UserTransactionCompletedById = currentUserId, UserTransactionIsForId = userIdFor, TransactionType = Convert.ToInt32(TransactionTypeEnum.CHARGE), AmountCharged = amount, TransactionStatusId = Convert.ToInt32(TransactionStatusEnum.PENDING) }; var trans = new TransactionsForReservations { DateLinked = DateTime.UtcNow, ReservationTransaction = resTransaction, }; var reservation = this.dbContext.ReservationGroup.FirstOrDefault(x => x.Id == reservationId); if (reservation.StatusId != Convert.ToInt32(ReservationGroupStatusEnum.PROCESSING)) { throw new Exception(); } reservation.StatusDate = DateTime.UtcNow; trans.ReservationGroupId = reservation.Id; this.dbContext.TransactionsForReservations.Add(trans); return(resTransaction); }
public HttpResponseMessage ProcessTransaction(IncomingProcessTransaction model) { return(ErrorFactory.Handle(() => { var userId = User?.Identity?.GetUserId(); if (string.IsNullOrWhiteSpace(userId)) { throw new Exception(); } var context = new PoolReservationEntities(); using (var unitOfWork = new UnitOfWork(context)) { PrepareAndGetReservationForProcessing_Result reservation = null; try { reservation = context.PrepareAndGetReservationForProcessing(model.ReservationId)?.FirstOrDefault(); } catch (Exception) { context.ChangeProcessingStatusToPending(model.ReservationId); } if (reservation == null) { try { context.ChangeProcessingStatusToPending(model.ReservationId); } catch (Exception) { } return JsonFactory.CreateJsonMessage(null, HttpStatusCode.NotFound, this.Request); } if (reservation.StatusId != Convert.ToInt32(ReservationGroupStatusEnum.PROCESSING)) { try { context.ChangeProcessingStatusToPending(model.ReservationId); } catch (Exception) { } return JsonFactory.CreateJsonMessage(new OutgoingMessage { Action = "wrongStatus" }, HttpStatusCode.NotFound, this.Request); } ReservationGroup reservationDBObject = null; try { reservationDBObject = unitOfWork.Reservations.GetReservationWithItems(userId, model.ReservationId); if (reservationDBObject == null) { return JsonFactory.CreateJsonMessage(null, HttpStatusCode.NotFound, this.Request); } } catch (Exception) { context.ChangeProcessingStatusToPending(model.ReservationId); } if (reservationDBObject.StatusId != Convert.ToInt32(ReservationGroupStatusEnum.PROCESSING)) { try { context.ChangeProcessingStatusToPending(model.ReservationId); } catch (Exception) { } return JsonFactory.CreateJsonMessage(new OutgoingMessage { Action = "wrongStatus" }, HttpStatusCode.NotFound, this.Request); } ReservationTransaction resTransaction = null; int stripeModifiedPriceInCents = 0; try { decimal priceToCharge = 0M; foreach (var item in reservationDBObject.ReserveItems) { if (item.IsDeleted == true) { continue; } priceToCharge += item.FinalPrice; } decimal stripeModifiedPrice = priceToCharge * 100.0M; stripeModifiedPriceInCents = (int)Math.Round(stripeModifiedPrice); //Must Update Repo If Changed. Rounds to the nearest penny. if (stripeModifiedPriceInCents <= 50) { return JsonFactory.CreateJsonMessage(new OutgoingMessage { Action = "noPriceToCharge" }, HttpStatusCode.NotFound, this.Request); } resTransaction = unitOfWork.Reservations.AddStripeChargeToPendingReservation(userId, userId, model.ReservationId, model.StripeTokenId, priceToCharge); unitOfWork.Complete(); } catch (Exception e) { context.ChangeProcessingStatusToPending(model.ReservationId); } string chargeId = null; try { if (resTransaction == null) { throw new Exception(); } var myCharge = new StripeChargeCreateOptions(); // always set these properties myCharge.Amount = stripeModifiedPriceInCents; myCharge.Currency = "usd"; // set this if you want to myCharge.Description = "JustMosey Reservation"; myCharge.SourceTokenOrExistingSourceId = model.StripeTokenId; // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later myCharge.Capture = true; var chargeService = new StripeChargeService(); StripeCharge stripeCharge = chargeService.Create(myCharge); chargeId = stripeCharge.Id; unitOfWork.Reservations.UpdateStripeSuccessfulChargeOnPendingReservation(userId, userId, resTransaction.Id, chargeId); unitOfWork.Complete(); } catch (Exception e) { try { var refundService = new StripeRefundService(); StripeRefund refund = refundService.Create(chargeId, new StripeRefundCreateOptions() { Amount = stripeModifiedPriceInCents, Reason = StripeRefundReasons.Unknown }); } catch (Exception) { } try { unitOfWork.Reservations.RefundStripeSuccessfulChargeOnPendingReservation(userId, userId, resTransaction.Id); unitOfWork.Complete(); } catch (Exception) { } try { } catch (Exception) { context.ChangeProcessingStatusToPending(model.ReservationId); } return JsonFactory.CreateJsonMessage(new OutgoingMessage { Action = "unknownErrorAfterProcessing" }, HttpStatusCode.InternalServerError, this.Request); } try { var updatedReservationDBObject = unitOfWork.Reservations.GetReservationWithItems(userId, model.ReservationId); var outgoingRes = OutgoingReservationGroup.Parse(updatedReservationDBObject); return JsonFactory.CreateJsonMessage(outgoingRes, HttpStatusCode.OK, this.Request); } catch (Exception) { return JsonFactory.CreateJsonMessage(null, HttpStatusCode.OK, this.Request); } } }, this.Request)); }