public IHttpActionResult PutHotelPayment(HotelPayment hotelPayment) { int id = hotelPayment.HotelPaymentId; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != hotelPayment.HotelPaymentId) { return(BadRequest()); } db.Entry(hotelPayment).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!HotelPaymentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostHotelPayment(HotelPayment hotelPayment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.HotelPayments.Add(hotelPayment); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = hotelPayment.HotelPaymentId }, hotelPayment)); }
public void ConfirmHotelBooking() { HotelsController hotelBook = new HotelsController(); HotelPayment payment = new HotelPayment(); object res = hotelBook.ConfirmHotelBooking(payment); payment.Location = "Chicago"; payment.HotelName = "abc"; Assert.IsNotNull(res); Assert.AreEqual("Chicago", payment.Location); Assert.IsNull(payment.paymentDetails); Assert.AreNotEqual("Michigan Ave", payment.HotelName); }
public IHttpActionResult DeleteHotelPayment(int id) { HotelPayment hotelPayment = db.HotelPayments.Find(id); if (hotelPayment == null) { return(NotFound()); } db.HotelPayments.Remove(hotelPayment); db.SaveChanges(); return(Ok(hotelPayment)); }
public Object ConfirmHotelBooking(HotelPayment hotelPayment) { try { using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString)) { connection.Open(); string sql = "INSERT INTO Payment(PaymentAmount,PaymentDate,StripePaymentID, UserID) VALUES(@param1,@param2,@param3,@param4); SELECT TOP 1 (PaymentID) from Payment order by PaymentID desc"; SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.Add("@param1", SqlDbType.Float).Value = hotelPayment.paymentDetails.PaymentAmount / 10000; cmd.Parameters.Add("@param2", SqlDbType.DateTime).Value = hotelPayment.paymentDetails.PaymentDate; cmd.Parameters.Add("@param3", SqlDbType.NVarChar).Value = hotelPayment.paymentDetails.StripePaymentID; cmd.Parameters.Add("@param4", SqlDbType.NVarChar).Value = hotelPayment.paymentDetails.UserID; cmd.CommandType = CommandType.Text; var newId = cmd.ExecuteScalar(); sql = "INSERT INTO HotelBooking(UserID,PaymentID,HotelName,NumberOfGuests,NumberOfRooms,Location,CheckInDate,CheckOutDate) VALUES(@param1,@param2,@param3,@param4,@param5,@param6,@param7,@param8); SELECT TOP 1 (HotelID) from HotelBooking order by HotelID desc"; cmd = new SqlCommand(sql, connection); cmd.Parameters.Add("@param1", SqlDbType.NVarChar).Value = hotelPayment.paymentDetails.UserID; cmd.Parameters.Add("@param2", SqlDbType.Int).Value = newId; cmd.Parameters.Add("@param3", SqlDbType.NVarChar).Value = hotelPayment.HotelName; cmd.Parameters.Add("@param4", SqlDbType.Int).Value = hotelPayment.NumberOfGuests; cmd.Parameters.Add("@param5", SqlDbType.NVarChar).Value = hotelPayment.NumberOfRooms; cmd.Parameters.Add("@param6", SqlDbType.NVarChar).Value = hotelPayment.Location; cmd.Parameters.Add("@param7", SqlDbType.NVarChar).Value = hotelPayment.CheckInDate; cmd.Parameters.Add("@param8", SqlDbType.NVarChar).Value = hotelPayment.CheckOutDate; cmd.CommandType = CommandType.Text; newId = cmd.ExecuteScalar(); connection.Close(); return(newId); } } catch (Exception ex) { Exceptions exceptions = new Exceptions(); exceptions.ExceptionMessage = "Error in BookFlight() :" + ex.InnerException; return(exceptions); } }
public HotelPaymentModel Create(HotelPayment hotelPayment) { return(new HotelPaymentModel() { HotelPaymentId = hotelPayment.HotelPaymentId, CardNumber = hotelPayment.CardNumber, NameOnCard = hotelPayment.NameOnCard, Month = (int)hotelPayment.Month, Year = (int)hotelPayment.Year, CVV = hotelPayment.CVV, AddressLine1 = hotelPayment.AddressLine1, AddressLine2 = hotelPayment.AddressLine2, PostalCode = hotelPayment.PostalCode, City = hotelPayment.City, Country = hotelPayment.Country, ContactNumber = hotelPayment.ContactNumber, ClientId = (int)hotelPayment.ClientId, CH_Id = (int)hotelPayment.CH_Id }); }