public ActionResult CreateBooking(int id, DateTime inputSDate, DateTime inputEDate) { ViewBag.FaultEx = ""; try { Advertisement ad = client.FindAdById(id); var userId = Session["ID"]; double result = client.CalcPrice(inputSDate, inputEDate, ad.Price); Booking b = new Booking { AdvertismentId = id, EndDate = inputEDate, RentUserId = Convert.ToInt32(userId), StartDate = inputSDate, TotalPrice = result, }; client.CreateBooking(b); return(RedirectToAction("SearchAds", "Ads")); } catch (FaultException e) { ViewBag.FaultEx = e.Message; return(RedirectToAction("ViewAd", "Ads", new { ID = id })); } catch (Exception) { return(RedirectToAction("Index", "Home")); } }
public void TestAddBooking() { Advertisement ad = new Advertisement { Title = "lorem 3", Description = "K0WJZFWWZW VLL4262TZI 81CS84SUUR OCWPGNS3X2 66WJ5APZLR BDCHCU3WEC", Price = 18.90, StartDate = DateTime.Now.Date, EndDate = DateTime.Now.AddDays(1).Date, UserID = userDB.GetAllUser().Last().Id, BikeId = bicycleDB.GetAllBicycles().Last().ID }; advertisementDB.AddAd(ad); var currentAd = advertisementDB.GetAllAds().Last(); Booking b = new Booking { AdvertismentId = currentAd.Id, StartDate = currentAd.StartDate, EndDate = currentAd.EndDate, RentUserId = userDB.GetAllUser().First().Id, TotalPrice = 50 }; client.CreateBooking(b); var booking = bookingDB.GetAllBookings().Last(); bookingDB.RemoveBooking(booking.Id); advertisementDB.RemoveAd(ad.Id); }