public ActionResult SpaceAdjustments([Bind(Include = "BookingId,GuestId")] Booking newBooking) { Booking currentBooking = Db.Bookings.SingleOrDefault(i => i.BookingId == newBooking.BookingId); if (currentBooking == null)//check if fetched data is valid { ViewBag.Errormessage = "Fetching data did not succeed. Please write down your bookingId before trying again."; return(PartialView("_SpaceForTent", newBooking)); } currentBooking.GuestId = Booking.checkForGuestNullReferenceException(newBooking.GuestId); if (currentBooking.GuestId == "Invalidstring")//check if fetched data is valid { ViewBag.Errormessage = "Sent data(GuestId) did not match. Please write down your bookingId before trying again."; return(PartialView("_SpaceForTent", newBooking)); } Camping currentSpot = Db.Camping.SingleOrDefault(i => i.ItemId == currentBooking.ItemId); if (currentSpot == null)//check if fetched data is valid { ViewBag.Errormessage = "Fetching data did not succeed. Please write down your bookingId before trying again."; return(PartialView("_SpaceForTent", newBooking)); } newBooking.BookingPrice = Booking.checkForNullReferenceException(currentSpot.CampingPrice); if (newBooking.BookingPrice == 0)//check if fetched data is valid { ViewBag.Errormessage = "Price for a Campingpot could not be fetched. Please write down your bookingId before trying again."; return(PartialView("_SpaceForTent", currentBooking)); } Db.SaveChanges(); return(PartialView("_SpaceForTent", currentBooking)); }
public static void ToggleTemporarySpawnPoint(CampingModPlayer modPlayer, int spawnX, int spawnY) { if (modPlayer.tentSpawn != new Point(spawnX, spawnY)) { if (IsTemporarySpawnObstructed(spawnX, spawnY)) { Camping.PrintInfo("CampTent.SpawnBlocked"); return; } Camping.PrintInfo("CampTent.SpawnSet"); modPlayer.tentSpawn = new Point(spawnX, spawnY); if (modPlayer.player == Main.LocalPlayer) { CampingModPlayer.SpawnAtTent = true; } } else { if (modPlayer.player.SpawnX == -1 && modPlayer.player.SpawnY == -1) { Camping.PrintInfo("CampTent.SpawnRemove"); } else { Camping.PrintInfo("CampTent.SpawnRemoveBed"); } modPlayer.tentSpawn = default; } }
public ActionResult DeleteConfirmed(int id) { Camping camping = db.Campings.Find(id); db.Campings.Remove(camping); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "idCamping,nombre,calle,provincia,numerocalle,codigopostal,descripcion,piscina,numeroplazas,numerobungalows")] Camping camping) { string currentUserId = User.Identity.GetUserId(); camping.UserId = currentUserId; if (ModelState.IsValid) { db.Entry(camping).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(camping)); }
// GET: Campings/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Camping camping = db.Campings.Find(id); string currentUserId = User.Identity.GetUserId(); if ((camping.UserId != currentUserId) || (camping == null)) { return(HttpNotFound()); } return(View(camping)); }
public int Save(Camping data) { int result = 0; #region UPDATE if (data.ID > 0) { try { using (var srv = new Datav3DBContext()) { var oldData = srv.Camping.FirstOrDefault(f => f.ID == data.ID); oldData.Name = data.Name; oldData.Latitude = data.Latitude; oldData.Longitude = data.Longitude; oldData.Description = data.Description; oldData.AuthorizedPersonel = data.AuthorizedPersonel; result = srv.SaveChanges() > 0 ? data.ID : 0; } } catch (Exception) { throw; } } #endregion #region INSERT else { try { using (var srv = new Datav3DBContext()) { data.IDate = DateTime.Now; data.IMainPartyID = 1; srv.Camping.Add(data); result = srv.SaveChanges() > 0 ? data.ID : 0; } } catch (Exception ex) { throw; } } #endregion return(result); }
public ActionResult SpaceForTent([Bind(Include = "BookingNeedsElectricity")] Booking newBooking) { Camping currentSpot = Db.Camping.FirstOrDefault(i => i.CampingElectricity == newBooking.BookingNeedsElectricity); newBooking.BookingStartDate = DateTime.Now; newBooking.BookingEndDate = DateTime.Now.AddDays(1); newBooking.BookingPrice = Booking.checkForNullReferenceException(currentSpot.CampingPrice); if (newBooking.BookingPrice == 0) { ViewBag.Errormessage = "Price for a Campingpot could not be fetched. Please try again."; } string pricePerNight = newBooking.BookingNeedsElectricity == true ? "Space without electricity costs " + newBooking.BookingPrice + " kr/Night/Person." : "Space with electricity costs " + newBooking.BookingPrice + " Kr/Night/Person."; ViewBag.pricePerNight = pricePerNight; return(PartialView("_SpaceForTent", newBooking)); }
public ActionResult ArrivalsDepartures() { List <ModifyBookingViewModel> arrivalsDepartures = new List <ModifyBookingViewModel>(); List <Booking> allBookings = Db.Bookings.ToList(); Booking currentBooking = new Booking(); ApplicationUser currentGuest = new ApplicationUser(); Camping currentItem = new Camping(); if (allBookings == null)//check if any data is recieved { ViewBag.Errormessage = "Fetching data did not succeed. Please try again."; return(PartialView("_ArrivalsDepartures")); } foreach (var booking in allBookings) { if ((booking.BookingStartDate.ToShortDateString() == DateTime.Now.ToShortDateString()) || (booking.BookingEndDate.ToShortDateString() == DateTime.Now.ToShortDateString())) { if ((booking.GuestHasReserved == true) || (booking.GuestHasCheckedIn == true)) { if ((booking.GuestId != null) && (booking.ItemId != 0)) { currentGuest = Db.Users.SingleOrDefault(i => i.Id == booking.GuestId); currentItem = Db.Camping.SingleOrDefault(i => i.ItemId == booking.ItemId); arrivalsDepartures.Add(new ModifyBookingViewModel { BookingId = booking.BookingId, BookingStartDate = booking.BookingStartDate, BookingEndDate = booking.BookingEndDate, GuestId = booking.GuestId, ItemId = booking.ItemId, ItemName = currentItem.ItemName, NumberOfGuests = booking.NumberOfGuests, BookingNeedsElectricity = booking.BookingNeedsElectricity, GuestFirstName = currentGuest.GuestFirstName, GuestLastName = currentGuest.GuestLastName, GuestHasCheckedIn = booking.GuestHasCheckedIn }); } } } } return(PartialView("_ArrivalsDepartures", arrivalsDepartures)); }
private void ConvertTent(Item item) { if (item.type == weaponOut.ItemType("CampTent")) { int stack = item.stack; item.type = ItemType <Items.Tents.CampTent>(); item.SetDefaults(item.type); item.stack = stack; Camping.Print("WeaponOutConvertor.ConvertTent"); } else if (item.type == weaponOut.ItemType("CampTentMakeshift")) { int stack = item.stack; item.type = ItemType <Items.Tents.CampTentMakeshift>(); item.SetDefaults(item.type); item.stack = stack; Camping.Print("WeaponOutConvertor.ConvertTent"); } }
public ActionResult AddNewCamping([FromBody] CampingRequestModel newRequest) { var time = DateTime.Now; var camping = new Camping { Owner = newRequest.Owner, Name = newRequest.Name, Description = newRequest.Description, ParkingType = newRequest.ParkingType, ParkingSize = newRequest.ParkingSize, Rating = newRequest.Rating, PricePerDay = newRequest.PricePerDay, URL = newRequest.URL, Id = newRequest.Id, CreateOn = time, facilities = newRequest.facilities, location = newRequest.location }; campingService.AddCamping(camping); return(Ok("Camping was created")); }
/// <summary> /// Gets a camping from the database (the ID is a Foreign key from another table) /// </summary> /// Reservation /// <param name="ID">ID for camping</param> /// <returns>Gets a camping that exists in the database null if not</returns> public static Camping GetSingleCamping(int ID) { Camping Camping = null; if (DatabaseConnectie.OpenConnection()) { try { DatabaseConnectie.OpenConnection(); SqlCommand cmd = new SqlCommand(); cmd.Connection = DatabaseConnectie.connect; cmd.CommandText = "SELECT * FROM Camping WHERE ID = @ID"; cmd.Parameters.Add(new SqlParameter("ID", ID)); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string Name = (reader["Naam"].ToString()); string Streetname = (reader["Straatnaam"].ToString()); string Location = (reader["Locatie"].ToString()); Camping = new Camping(ID, Name, Streetname, Location); } return(Camping); } catch (SqlException e) { Console.WriteLine("Query Failed: " + e.StackTrace + e.Message.ToString()); } finally { DatabaseConnectie.CloseConnection(); } } return(Camping); }
public Camping GetByID(int ID) { Camping result = new Camping(); if (ID > 0) { using (var srv = new Datav3DBContext()) { //yourObjectContext.ContextOptions.LazyLoadingEnabled = false; srv.Configuration.LazyLoadingEnabled = false; result = srv.Camping .Include("RelPropertyValueCamping") .Include("Comments") //.Include("Comments.MainParty") .Include("Contact") //.Include("Contact.ContactType") .Include("File") .FirstOrDefault(w => w.ID == ID); result.File = result.File.Where(w => w.TypeID == 1).ToList(); } } //var asd = GetByIDForMaps(ID); return(result); }
public void DeleteCamping(Camping camping) { db.Camping.Remove(camping); }
public void AddCamping(Camping camping) { db.Camping.Add(camping); db.SaveChanges(); }
public ActionResult CheckInConfirmation(int BookingId, int NumberOfCheckInGuests) { if (ModelState.IsValid) { Booking currentBooking = Db.Bookings.SingleOrDefault(i => i.BookingId == BookingId); Camping currentSpot = Db.Camping.SingleOrDefault(i => i.ItemId == currentBooking.ItemId); ApplicationUser currentGuest = Db.Users.SingleOrDefault(i => i.GuestId == currentBooking.GuestId); int numberOfDays = 0; if ((currentBooking == null) || (currentSpot == null) || (currentGuest == null))//check if fetched data is valid { ViewBag.Errormessage = "Fetching of data did not succeed. Please try again."; return(PartialView("_FailedCheckIn")); } BookingGuestViewModel checkInBooking = new BookingGuestViewModel { BookingId = currentBooking.BookingId, BookingPrice = currentBooking.BookingPrice, GuestFirstName = currentGuest.GuestFirstName, GuestLastName = currentGuest.GuestLastName, GuestId = currentGuest.GuestId, ItemId = currentSpot.ItemId, ItemName = currentSpot.ItemName, NumberOfGuests = currentBooking.NumberOfGuests }; if (currentBooking.NumberOfGuests != NumberOfCheckInGuests) //Check if PartySize differ from reservation { currentGuest.GuestHasToPay = currentGuest.GuestHasToPay - currentBooking.BookingPrice; numberOfDays = Booking.CalculateNumberOfDays(currentBooking.BookingStartDate, currentBooking.BookingEndDate); currentBooking.BookingPrice = currentSpot.CampingPrice * NumberOfCheckInGuests * numberOfDays; currentGuest.GuestHasToPay = currentGuest.GuestHasToPay + currentBooking.BookingPrice; currentBooking.GuestHasCheckedIn = true; currentBooking.GuestHasReserved = false; currentBooking.NumberOfGuests = NumberOfCheckInGuests; currentSpot.ItemIsOccupied = true; int numberOfSaves = Db.SaveChanges(); if (numberOfSaves != 3) { ViewBag.Errormessage = "The Checkin failed! Please check the number of checked in persons and the cost for the stay."; return(PartialView("_FailedCheckIn", checkInBooking)); } checkInBooking.BookingPrice = currentBooking.BookingPrice; checkInBooking.NumberOfGuests = NumberOfCheckInGuests; return(PartialView("_CheckInConfirmation", checkInBooking)); } else { currentBooking.GuestHasCheckedIn = true; currentBooking.GuestHasReserved = false; currentSpot.ItemIsOccupied = true; int numberOfSaves = Db.SaveChanges(); if (numberOfSaves != 2) { ViewBag.Errormessage = "The Checkin failed! Please check the number of checked in persons and the cost for the stay."; return(PartialView("_FailedCheckIn", checkInBooking)); } return(PartialView("_CheckInConfirmation", checkInBooking)); } } else { ViewBag.Errormessage = "The check out did not recive correct indata. Please try again."; return(PartialView("_FailedCheckIn")); } }
public ActionResult CheckOutConfirmation([Bind(Include = "BookingId,NumberOfGuests")] BookingGuestViewModel checkingOutGuest) { if (ModelState.IsValid) { List <Booking> allBookings = Db.Bookings.ToList(); Booking departingBooking = Db.Bookings.SingleOrDefault(i => i.BookingId == checkingOutGuest.BookingId); ApplicationUser departingGuest = Db.Users.SingleOrDefault(i => i.GuestId == departingBooking.GuestId); Camping departedGuestSpot = Db.Camping.SingleOrDefault(i => i.ItemId == departingBooking.ItemId); List <Booking> allGuestBookings = new List <Booking>(); BookingGuestViewModel departingGuestBooking = new BookingGuestViewModel(); List <LinkBooking> allLinkBookings = Db.LinkBookings.ToList(); if ((allBookings == null) || (allLinkBookings == null)) //check if any data is received { ViewBag.Errormessage = "Fetching of data did not succeed. Please try again."; return(PartialView("_CheckOut")); } if ((departingBooking == null) || (departedGuestSpot == null) || (departingGuest == null))//check if fetched data is valid { ViewBag.Errormessage = "No booking, spot or guest could be found. Please try again."; return(PartialView("_CheckOut")); } foreach (var booking in allBookings) //collect any other bookings the guest have made { if ((booking.GuestId == departingGuest.GuestId) && ((booking.GuestHasCheckedIn == true) || booking.GuestHasReserved == true)) { allGuestBookings.Add(booking); } } if (allGuestBookings.Count == 1)//if no other bookings exist { departingGuest.GuestHasCheckedIn = false; departingGuest.GuestHasReserved = false; departingGuest.GuestHasPaid = departingGuest.GuestHasPaid + departingBooking.BookingPrice; departingGuest.GuestHasToPay = departingGuest.GuestHasToPay - departingBooking.BookingPrice; departingBooking.GuestHasCheckedIn = false; departingBooking.GuestHasReserved = false; departingBooking.BookingIsPaid = true; departedGuestSpot.ItemIsOccupied = false; if (Db.SaveChanges() != 3) { ViewBag.Errormessage = "The check out did partly succed."; return(PartialView("_CheckOutConfirmation", checkingOutGuest)); } } else //if more bookings exist handle the specific booking. { departingGuest.GuestHasPaid = departingGuest.GuestHasPaid + departingBooking.BookingPrice; departingGuest.GuestHasToPay = departingGuest.GuestHasToPay - departingBooking.BookingPrice; departingBooking.GuestHasCheckedIn = false; departingBooking.GuestHasReserved = false; departingBooking.BookingIsPaid = true; departedGuestSpot.ItemIsOccupied = false; } int numberOfSaves = Db.SaveChanges(); if (numberOfSaves != 3) { ViewBag.Errormessage = "The check out did partly succed."; return(PartialView("_FailedCheckOut", checkingOutGuest)); } departingGuestBooking.BookingId = departingBooking.BookingId; departingGuestBooking.GuestFirstName = departingGuest.GuestFirstName; departingGuestBooking.GuestLastName = departingGuest.GuestLastName; departingGuestBooking.BookingPrice = departingBooking.BookingPrice; departingGuestBooking.NumberOfGuests = departingBooking.NumberOfGuests; departingGuestBooking.ItemName = departedGuestSpot.ItemName; return(PartialView("_CheckOutConfirmation", departingGuestBooking)); } else { ViewBag.Errormessage = "The check out did not recive correct indata. Please try again."; return(PartialView("_FailedCheckOut", checkingOutGuest)); } }
public ActionResult RentSpaceForTent([Bind(Include = "BookingStartDate,BookingEndDate," + "NumberOfGuests,BookingNeedsElectricity,BookingId,GuestId")] Booking newBooking) { if (ModelState.IsValid) { int numberOfDays = 0; List <Booking> currentBookings = Db.Bookings.ToList(); //Gather all present bookings in a list. List <int> notEligibleSpots = new List <int>(); //list of invalid spotnumbers List <Camping> ListOfSpots = new List <Camping>(); //list of valid spots Booking updatedBooking = new Booking(); ViewBag.Errormessage = ""; HttpCookie campingCookie = new HttpCookie("CampingCookie"); if (currentBookings == null) { ViewBag.Errormessage = "Fetching data did not succeed. Please try again."; return(PartialView("_SpaceForTent", newBooking)); } if (newBooking.BookingId != 0)//a reservation readjustment have to exclude its own reservation { for (int i = currentBookings.Count - 1; i >= 0; i--) { if (currentBookings[i].BookingId == newBooking.BookingId) { currentBookings.Remove(currentBookings[i]); newBooking.ItemId = 0;// } } } ListOfSpots = Booking.FetchCampingSpots(newBooking.BookingNeedsElectricity); if (ListOfSpots[0].CampingSpot == "NoData") { ViewBag.Errormessage = "Fetching campingdata did not succeed. Please try again."; return(PartialView("_SpaceForTent", newBooking)); } if (newBooking.BookingStartDate >= newBooking.BookingEndDate)//check the start and end dates so start is before end. { ViewBag.Errormessage = "You must arrive before you can depart. Please choose another start and/or end date."; newBooking.BookingPrice = ListOfSpots[0].CampingPrice; return(PartialView("_SpaceForTent", newBooking)); } if (currentBookings.Capacity == 0) //check if any bookings is present { newBooking.ItemId = ListOfSpots[0].ItemId; //if no bookings is present choose the first spot } else { foreach (var booking in currentBookings) //gather the spots that is reserved in other bookings during the new bookings timeframe. { if ((newBooking.BookingStartDate >= booking.BookingEndDate) || (newBooking.BookingEndDate <= booking.BookingStartDate)) //if the new bookings startdate is between the booked spots start and end date { } else { notEligibleSpots.Add(booking.ItemId); } } notEligibleSpots.Sort(); ListOfSpots = Camping.RemoveOccupiedSpots(ListOfSpots, notEligibleSpots); if (ListOfSpots.Count == 0) //if no spots remains send a message to user that camping is full { ViewBag.Errormessage = "There is no available space for you. Please choose another arrivaldate and departuredate."; return(PartialView("_SpaceForTent", newBooking)); } newBooking.ItemId = ListOfSpots[0].ItemId; } numberOfDays = Booking.CalculateNumberOfDays(newBooking.BookingStartDate, newBooking.BookingEndDate); //Calculate number of days newBooking.BookingPrice = ListOfSpots[0].CampingPrice * numberOfDays * newBooking.NumberOfGuests; //Calculate the price for the guest if (newBooking.BookingId == 0) //Save to database current info if a new reservation and not a readjusted reservation { Db.Bookings.Add(newBooking); } else //if a booking exist update the booking with the new values { updatedBooking = Db.Bookings.SingleOrDefault(i => i.BookingId == newBooking.BookingId); updatedBooking.BookingStartDate = newBooking.BookingStartDate; updatedBooking.BookingEndDate = newBooking.BookingEndDate; updatedBooking.NumberOfGuests = newBooking.NumberOfGuests; updatedBooking.BookingNeedsElectricity = newBooking.BookingNeedsElectricity; updatedBooking.BookingPrice = newBooking.BookingPrice; updatedBooking.ItemId = newBooking.ItemId; Db.SaveChanges(); } int checkDbSave = Db.SaveChanges(); if ((checkDbSave < 1) && (newBooking.GuestId == null))//Check is database save was ok { ViewBag.Errormessage = "Your booking could not be processed. Please try again later."; return(PartialView("_SpaceForTent", newBooking)); } //cookiedetails is set here campingCookie["BookingId"] = Convert.ToString(newBooking.BookingId); campingCookie.Expires = DateTime.Now.AddDays(30); Response.Cookies.Add(campingCookie); return(PartialView("_ConfirmSpaceForTent", newBooking)); } else { ViewBag.Errormessage = "Some of your submited values were incorrect. Please try again later."; return(PartialView("_SpaceForTent", newBooking));//return previous view as indata is invalid } }