Example #1
0
        public void GetPromoCodeByCode_Test()
        {
            //arrange
            PromoCode expected = new PromoCode(2);
            //act
            PromoCode actual = PromoCode.GetPromoCode("TestPromo");

            //assert
            Assert.Equal(expected.PromoId, actual.PromoId);
        }
        public double GetDiscountPrice(string roomType, int days, string promo)
        {
            var initialPrice = GetRoomPrice(roomType, days);

            // Retrieve PromoCode Object
            PromoCode resPromoCode = _promoCodeService.GetPromoCode(promo);

            // get the last two digit of the promo Code which will be the discount % and factor into room price
            var discount = (int)resPromoCode.GetPromoCode()["discount"];

            return(initialPrice - (initialPrice * (discount / 100.0)));
        }
Example #3
0
 public IHttpActionResult AddPromo(long id, string code)
 {
     try
     {
         Ride ride = new Ride(id);
         return(Ok(ride.AddPromo(PromoCode.GetPromoCode(code))));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Example #4
0
 public ActionResult ClosePromo(string code)
 {
     try
     {
         PromoCode promo = PromoCode.GetPromoCode(code);
         promo.IsOpen = false;
         return(RedirectToAction("ViewPromos"));
     }
     catch (Exception ex)
     {
         return(RedirectToAction("ErrorPage", "Error", ex));
     }
 }
Example #5
0
 public ActionResult RiderDetails(BookRideViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     try
     {
         //create rider
         Rider rider = new Rider(new User.NameFormat {
             FirstName = model.RiderFirstName, LastName = model.RidierLastName
         }, new User.ContactNumberFormat(model.CountryCode, model.CompanyCode, model.Number));
         //Book Ride
         var ride = rider.BookRide(new Ride.RideBookingDetails
         {
             Destination = new Location {
                 Latitude = model.DLat, Longitude = model.Dlng
             },
             PickUpLocation = new Location {
                 Latitude = model.PLat, Longitude = model.Plng
             },
             VehicleType = new VehicleType(model.VehicleType)
         });
         //Add Promo
         if (model.PromoCode != null || model.PromoCode == String.Empty)
         {
             ride.AddPromo(PromoCode.GetPromoCode(model.PromoCode));
         }
         return(RedirectToAction("BookRide"));
     }
     catch (UniqueKeyViolationException ex)
     {
         ModelState.AddModelError(String.Empty, ex.Message);
         return(View(model));
     }
     catch (UnsuccessfullProcessException)
     {
         ModelState.AddModelError(String.Empty, "Seems like no driver is available near the pick-up point.");
         return(View(model));
     }
     catch (Exception ex)
     {
         return(RedirectToAction("ErrorPage", "Error", ex));
     }
 }