public void ForbiddenResource() { repo.Add(b); repo.Save(); using (UserManager <Client, int> manager = new ClientUserManager(new CustomUserStore(ctx))) { Assert.IsNull(repo.GetBookingById(b.Id, manager.FindByEmail("*****@*****.**").Id)); } }
protected void RejectUpgrade_OnClick(object sender, EventArgs e) { int bookingId = 0; if (Session[Constant.UpgradeKey] != null) { int bookingsTempId = int.Parse(Session[Constant.UpgradeKey].ToString()); var bookingsTemp = _productRepository.GetBookingsTempById(bookingsTempId); if (bookingsTemp != null) { var booking = Mapper.Map <BookingsTemps, Bookings>(bookingsTemp.Item1); var products = _bookingRepository.ProductList .FirstOrDefault(p => p.ProductId == booking.ProductId); var hotels = _bookingRepository.HotelList .FirstOrDefault(h => h.HotelId == (products != null ? products.HotelId : 0)); var markets = (from m in _productRepository.MarketList join mh in _productRepository.MarketHotelList on m.Id equals mh.MarketId where mh.HotelId == (hotels != null ? hotels.HotelId : 0) && m.IsActive select m).FirstOrDefault(); var creditLogDescription = string.Format("{0} – {1} – {2} – ", products != null ? products.ProductName : "", hotels != null ? hotels.HotelName : "", markets != null ? markets.LocationName : ""); int discountId = bookingsTemp.Item2 != null ? bookingsTemp.Item2.DiscountId : 0; var addParam = new AddBookingParams { BookingObject = booking, DiscountId = discountId, CustomerCreditObject = _customerCredits, Description = creditLogDescription }; bookingId = _bookingRepository.Add(addParam); } } CacheLayer.Clear(CacheKeys.BookingsCacheKey); CacheLayer.Clear(CacheKeys.CustomerInfosCacheKey); CacheLayer.Clear(CacheKeys.DiscountsCacheKey); CacheLayer.Clear(CacheKeys.DiscountBookingsCacheKey); CacheLayer.Clear(CacheKeys.SurveysCacheKey); Session.Remove(Constant.UpgradeKey); Response.Redirect(string.Format(Constant.ConfirmProductPage, Page.RouteData.Values["market"], Page.RouteData.Values["city"], Page.RouteData.Values["hotelName"], Page.RouteData.Values["productName"], bookingId)); }
public void CreateBooking(Booking Booking) { BookingRepository bookingRepo = new BookingRepository(); try { bookingRepo.Add(Booking); GlobalUnitOfWork.Commit(); } catch (Exception ex) { throw ex; } }
public void CheckOut(Booking booking) { try { PurchaseCuisine(); _bookingRepository.Add(booking); _bookingRepository.Save(); booking.BookingContent = _cart.ToString(); AfterBooking?.Invoke(booking); } catch (Exception ex) { ValidationDictionary.AddGeneralError(ex.Message); } }
public void Booking_AddNew_Seats_Available() { BookingRepository repository = new BookingRepository(dbConnectionString); var rndDays = new Random().Next(1, 30); Booking booking = new Booking { TravelDate = DateTime.Now.Date.AddDays(rndDays), FlightId = 8, PassengerId = 6, PassengerCount = 1 }; var result = repository.Add(booking); Assert.AreEqual(1, result); }
public async Task <bool> Execute(BookingRequest bookingRequest) { var booking = new Booking { IdHotel = bookingRequest.HotelId, ClientEmail = bookingRequest.UserId, CheckInDate = bookingRequest.From, CheckOutDate = bookingRequest.To, TotalCost = bookingRequest.Price, NumberOfAdults = bookingRequest.Adults, NumberOfChildren = bookingRequest.Kids, NumberOfBabies = bookingRequest.Babies, IdRoomType = bookingRequest.RoomType }; _bookingRepostiory.Add(booking); await _uow.SaveChangesAsync(); return(true); }
public ActionResult Create([Bind(Include = "App_Id,P_Details,App_Status,App_Date,Dep,App_Time,Reason,isFree,TimeId")] Booking booking, string id, string Emp) { var result = DateTime.Compare(DateTime.Now, booking.AppDate); var errorMessage = ""; var repository = new DefyClinicRepository(); var contxet = new DefyClinicContxet(); //Appointment newTime = db.Appointments.Find(appointment.TimeId); //Appointment newDate = db.Appointments.Find(appointment.BookDate); var sTime = db.GetBookings().FirstOrDefault(p => p.TimeId == booking.TimeId)?.TimeId; var sDate = db.GetBookings().FirstOrDefault(p => p.AppDate == booking.AppDate)?.AppDate; var userId = ""; ViewBag.App_Time = repository.GetSlots() .Where(w => w.Status && w.Date.ToString() == id) .AsEnumerable() .Select(i => new SelectListItem { Value = i.A_Slot.ToShortTimeString(), Text = i.A_Slot.ToShortTimeString() }); // ViewBag.App_Time = new SelectList(d.GetSlots().Where(X => X.Status == true && X.Date.ToString() == id), "Id", "A_Slot"); ViewData["App_Date"] = repository.GetSlots() .Where(w => w.Status) .AsEnumerable() .Select(i => new SelectListItem { Value = i.Date.ToShortDateString(), Text = i.Date.ToShortDateString() }); // ViewBag.App_Time = d.GetSlots().Where(X => X.Status == true).SingleOrDefault().A_Slot.ToShortTimeString(); // ViewData["App_Date"] = new SelectList(d.GetSlots().Where(X => X.Status == true), "Id", "Date"); // ViewData["App_Date"] = d.GetSlots().Where(X => X.Status == true).SingleOrDefault().Date.ToShortDateString(); // ViewBag.App_Time = new SelectList(db.BookingSlots.Where(X => X.Date.ToString() == id), "BS_Id", "StartTime"); userId = Emp ?? HttpContext.User.Identity.Name; var pNo = contxet.Staffs.Single(x => x.EmpEmail == userId).EmpNo; var pTitle = contxet.Staffs.Single(x => x.EmpEmail == userId).Title; var pName = contxet.Staffs.Single(x => x.EmpEmail == userId).EmpName; var pSurname = contxet.Staffs.Single(x => x.EmpEmail == userId).EmpSurname; var pGender = contxet.Staffs.Single(x => x.EmpEmail == userId).Gender; var pMobile = contxet.Staffs.Single(x => x.EmpEmail == userId).EmpTel; var pId = contxet.Staffs.Single(x => x.EmpEmail == userId).ID_Pass; var dep = contxet.Staffs.Single(x => x.EmpEmail == userId).Department.D_Name; ViewBag.P_Name = $"{pTitle} {pName} {pSurname}"; ViewBag.P_Gender = pGender; ViewBag.P_No = pNo; ViewBag.P_Mobiel = pMobile; ViewBag.P_ID = pId; ViewBag.Dep = dep; if (ModelState.IsValid) { var b = new Booking { PatientDetails = HttpContext.User.Identity.Name, AppDate = booking.AppDate, TimeId = booking.TimeId, AppStatus = "Not Yet Confirmed", AppId = booking.AppId, AppTime = booking.AppTime, Reason = booking.Reason, IsFree = true }; db.Add(booking); return(RedirectToAction("Index")); } return(View(booking)); }
public OpenBookingResponse OpenBooking(int vehicleId, int accountId) { //this method allows a car to be checked ou //check car exists and is correct status var car = CarRepository.Find(vehicleId); if (car == null) { return new OpenBookingResponse { Message = $"Vehicle {vehicleId} does not exist", Success = false } } ; if (car.Status != Constants.CarAvailableStatus) { return new OpenBookingResponse { Message = $"{car.Make} {car.Model} is not available to " + "be booked", Success = false } } ; //check user exists and correct status var user = UserRepository.Find(accountId); if (user == null) { return new OpenBookingResponse { Message = $"Account {accountId} does not exist", Success = false } } ; if (user.Status != Constants.UserActiveStatus) { return new OpenBookingResponse { Message = "Only activated users can book cars", Success = false } } ; //check is payment method exists var payment = PaymentMethodRepository.Find(accountId); if (payment == null) { return new OpenBookingResponse { Message = "You enter a payment method before booking", Success = false } } ; //sanity check to ensure the vehicle has no other bookings var hasOpenVehicleBookings = BookingRepository .FindByVehicleId(vehicleId) .Any(x => x.BookingStatus == Constants.BookingOpenStatus); if (hasOpenVehicleBookings) { //update the status of the car to be booked car.Status = Constants.CarBookedStatus; CarRepository.Update(car); return(new OpenBookingResponse { Message = $"{car.Make} {car.Model} is not available " + $"to be booked", Success = false }); } //sanity check to ensure the account has no other bookings var hasOpenAccountBookings = BookingRepository .FindByAccountId(accountId) .Any(x => x.BookingStatus == Constants.BookingOpenStatus); if (hasOpenAccountBookings) { return new OpenBookingResponse { Message = "User already has an open vehicle booking", Success = false } } ; var category = car.CarCategory1; if (category == null) { category = CarCategoryRepository.Find(car.CarCategory); if (category == null) { return new OpenBookingResponse { Message = "Car has an invalid category and can not " + "be checked out", Success = false } } ; } //create the booking and save var booking = new Booking { VehicleID = vehicleId, AccountID = accountId, BookingStatus = Constants.BookingOpenStatus, BillingRate = category.BillingRate, CheckOut = DateTime.Now, CityPickUp = car.Suburb }; BookingRepository.Add(booking); //update the status of the car to be booked car.Status = Constants.CarBookedStatus; CarRepository.Update(car); return(new OpenBookingResponse { BookingId = booking.BookingID, CheckOutTime = booking.CheckOut.ToString(), Success = true, Message = $"{car.Make} {car.Model} has been booked out " + $"at ${category.BillingRate} per hour" }); }
public IActionResult Book([FromBody] Booking bookingRequest) { if (!(bookingRequest.PassengerCount > 0)) { return(BadRequest("At least 1 passenger is required.")); } Flight flight = flightRepository.Find(bookingRequest.FlightId); if (flight == null || flight.PassengerCapacity <= 0) { return(BadRequest("Invalid Flight.")); } Passenger passenger = passengerRepository.Find(bookingRequest.PassengerId); if (passenger == null || string.IsNullOrWhiteSpace(passenger.IdentityNumber)) { return(BadRequest("Invalid Passenger.")); } if (bookingRequest.PassengerCount > flight.PassengerCapacity) { return(BadRequest("Passenger Capacity exceeded.")); } Booking booking = bookingRepository.Find(bookingRequest.TravelDate, bookingRequest.FlightId, bookingRequest.PassengerId); if (booking != null && booking.PassengerCount > 0) { return(BadRequest("Flight already booked for the same travel day by the same passenger.")); } else { // Valid booking request, so proceed. bookingRepository.Add(bookingRequest); } FlightBooking flightBooking = flightBookingRepository.Find(bookingRequest.FlightId, bookingRequest.TravelDate); if (flightBooking != null && flightBooking.FlightBookingId > 0) { var currentPassengerCount = flightBooking.PassengerCount; if ((currentPassengerCount + bookingRequest.PassengerCount) > flight.PassengerCapacity) { return(BadRequest("Passenger Capacity exceeded.")); } else { // Valid passenger count. flightBooking.PassengerCount = (short)(currentPassengerCount + bookingRequest.PassengerCount); flightBookingRepository.Update(flightBooking); } } if (flightBooking == null || flightBooking.FlightBookingId <= 0) { flightBooking = new FlightBooking { TravelDate = bookingRequest.TravelDate, FlightId = bookingRequest.FlightId, PassengerCount = bookingRequest.PassengerCount }; // Valid booking request, so proceed. flightBookingRepository.Add(flightBooking); } return(Ok("Flight Booked.")); }