public async Task <string> VerifyReservationId(VerificationReservationId verificationtion) { var response = await _rpcBus.Rpc.RequestAsync <string, string>(JsonConvert.SerializeObject(verificationtion), c => c.WithQueueName(nameof(VerificationReservationId))); return(response); }
public async Task <string> VerifyReservationId(VerificationReservationId verification) { var verifyReservationId = verification.ReservationId; var verifyUserId = Guid.Parse(verification.UserId); var verify = Guid.Parse(verifyReservationId); var filter = Builders <Reservation> .Filter.Eq("Id", verify); var reservation = _reservation.Find(filter).FirstOrDefault(); if (reservation == null) { var errBook = "Book doesn't existst"; var serializeBook = JsonConvert.SerializeObject(errBook); return(serializeBook); } if (verifyUserId == reservation.UserId) { var senderReservation = new SenderReservation() { RoomId = reservation.RoomId, ReservStartDate = reservation.ReservStartDate, ReservFinishedDate = reservation.ReservFinishedDate, NumberOfNights = reservation.NumberOfNights, AmountPaid = reservation.AmountPaid }; var send = JsonConvert.SerializeObject(senderReservation); return(send); } var errorSend = "User doesn't existst"; var err = JsonConvert.SerializeObject(errorSend); return(err); }
public async Task <string> PayRoom(OrderRequestModel model) { try { if (model.ReservationId == null) { throw new Exception("operation is impossible without Id"); } var userId = _headerService.GetUserId(); if (userId == null) { throw new Exception("operation is impossible without Id"); } var verify = new VerificationReservationId() { ReservationId = model.ReservationId.ToString(), UserId = userId.ToString() }; var reservation = await _publisher.VerifyReservationId(verify); var receiveReservation = JsonConvert.DeserializeObject <ReceiveReservation>(reservation); var amountPaid = receiveReservation.AmountPaid.ToString(); var pay = new PaymentModel() { AmountPaid = amountPaid, UserId = userId.ToString() }; var message = await _publisher.PayRoom(pay); var m = "spspspsps"; var mmm = "rtrtrtrtrtrtr"; if (message == m) { throw new Exception(message); } if (message == mmm) { throw new Exception(message); } var errorMessage = "I'm sorry, but it appears your account has insufficient funds"; if (message == errorMessage) { throw new Exception(message); } var dateOfPayment = DateTime.UtcNow; var newOrder = new Order() { Id = Guid.NewGuid(), UserId = userId, RoomId = receiveReservation.RoomId, ReservStartDate = receiveReservation.ReservStartDate, ReservFinishDate = receiveReservation.ReservFinishedDate, DateOfPayment = dateOfPayment, AmountPaid = receiveReservation.AmountPaid, }; await _orderRepository.AddOrderAsync(newOrder); var payment = new Payment() { ReservationId = model.ReservationId.ToString() }; await _publisher.PublishPayment(payment); return(message); } catch (Exception ex) { _logger.LogError(ex, "faild orderService"); throw; } }