public ActionResult Reserve(ReservationModel reserveModel) { if (reserveModel == null) { return(HttpNotFound()); } tAtrakcjeUslugi attraction = reserveModel.Attraction; int? clientId = AuthorizeUtil.GetUserId(service, User); if (clientId == null) { return(RedirectToAction("Login", "Account")); } ConfigureViewBag(attraction, clientId); try { if (service.IsOfferReserved(attraction.IDOferty, clientId)) { if (!service.IsAttractionReserved(attraction.IDAtrakcjiUslugi, reserveModel.PersonId, clientId.Value)) { service.ReserveAttraction(attraction.IDAtrakcjiUslugi, reserveModel.PersonId, clientId.Value); } ViewBag.ReserveMessage = "Attraction is reserved"; } else { ModelState.AddModelError("", "Offer is not reserved. To reserve attraction reserve offer first."); } } catch (Exception ex) { ModelState.AddModelError("", "Failed to reserve offer: " + ex.Message); } return(View(reserveModel)); }
protected void ConfirmButton_Click(object sender, EventArgs e) { int attractionId; if (int.TryParse(AttractionId.Value, out attractionId)) { var attraction = service.FindAttraction(attractionId); if (attraction != null) { if (IsOfferReserved(attraction.IDAtrakcjiUslugi)) { int?userId = AuthorizeUtil.GetUserId(service, User); if (userId == null) { Response.Redirect("~/Account/Login"); } pnlConfirm.Visible = false; if (!IsAttractionReserved(attractionId)) { tKlient client = service.GetClientWithPersons(userId.Value); int personId = client.tOsoby.First().IDOsoby; service.ReserveAttraction(attractionId, personId, client.IDKlienta); } Message.Text = "Offer has been reserved."; } else { pnlConfirm.Visible = false; Message.Text = "Offer related to this attraction has to be reserved first."; } } } }
public void ReserveAttraction() { service.ClearReservationTables(); service.Save(); bool actual = service.IsAttractionReserved(1, 1, 1); Assert.IsFalse(actual); service.ReserveOffer(19, 1, 1); // Reserve attraction service.ReserveAttraction(1, 1, 1); actual = service.IsAttractionReserved(1, 1, 1); Assert.IsTrue(actual); }