public HolidayBooking(int travelerId, Stay stay, DateTime booked) { this.TravelerId = travelerId; this.Stay = stay; this.Booked = booked; this.Id = GenerateId(travelerId, stay.FirstNight, stay.LastNight, booked); }
//show the stay info public ActionResult ExitStay(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Stay stay = db.Stays.Find(id); if (stay == null) { return(HttpNotFound()); } ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "nome", stay.ClientId); ViewBag.nr = new SelectList(db.Rooms, "nr", "nr", stay.nr); //client data var clientData = db.Clients.Find(stay.ClientId); ViewBag.clientData = clientData; //room data and stay cost var roomData = db.Rooms.Find(stay.nr); ViewBag.roomData = roomData; TimeSpan timeSpan = DateTime.Now.Date.Subtract(stay.EntryDate.Date); ViewBag.timeSpan = Math.Abs(timeSpan.TotalDays); stay.cost_paid = (decimal)timeSpan.TotalDays * roomData.custo_dia; stay.ExitDate = DateTime.Now.Date; return(View(stay)); }
public IActionResult Post(int custId, [FromBody] Stay stay) { if (ModelState.IsValid) { var customer = _ctx.Customers.Where(c => c.Id == custId).FirstOrDefault(); if (customer == null) { return(NotFound()); } var room = _ctx.Rooms.Where(r => r.Id == stay.Room.Id).FirstOrDefault(); if (room == null) { return(NotFound()); } stay.Guest = customer; stay.Room = room; _ctx.Stays.Add(stay); _ctx.SaveChanges(); return(Created($"api/customers/{custId}/stays/{stay.Id}", stay)); } return(BadRequest()); }
public static Stay GetStay(int stayid) { Stay s = null; using (SqlConnection conn = Connection.GetConnection()) { if (conn != null) { SqlCommand cm = new SqlCommand("select * from Stay where StayID = @stayid", conn); cm.Parameters.AddWithValue("@stayid", stayid); var rs = cm.ExecuteReader(); if (rs.HasRows) { while (rs.Read()) { s = new Stay(); s.StayID = rs[0] as int? ?? 0; s.BookingID = rs[1] as int? ?? 0; s.GuestID = rs[2] as int? ?? 0; s.FromDate = rs[3] as DateTime? ?? null; s.ToDate = rs[4] as DateTime? ?? null; } } } } return(s); }
public Stay GenerateStay(ChonkData chonk) { Stay stay = new Stay(); stay.guestName = chonk.name; return(stay); }
public ActionResult ExitStay([Bind(Include = "StayId,EntryDate,ExitDate,cost_paid,ClientId,nr")] Stay stay) { if (ModelState.IsValid) { db.Entry(stay).State = EntityState.Modified; stay.ExitDate = DateTime.Now.Date; //change the room state var room = db.Rooms.Find(stay.nr); room.estado = true; db.Entry(room).CurrentValues.SetValues(room); //save all changes db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "nome", stay.ClientId); ViewBag.nr = new SelectList(db.Rooms, "nr", "nr", stay.nr); //client data var clientData = db.Clients.Find(stay.ClientId); ViewBag.clientData = clientData; //room data and stay cost var roomData = db.Rooms.Find(stay.nr); ViewBag.roomData = roomData; TimeSpan timeSpan = DateTime.Now.Date.Subtract(stay.EntryDate.Date); ViewBag.timeSpan = Math.Abs(timeSpan.TotalDays); stay.cost_paid = (decimal)timeSpan.TotalDays * roomData.custo_dia; stay.ExitDate = DateTime.Now.Date; return(View(stay)); }
public ActionResult <Stay> UpdateStay(int id, [FromBody] Stay stay) { Console.WriteLine("Update w/ id " + id); stay.ID = id; _stayService.SaveStay(stay); return(Ok(stay)); }
public IActionResult Put(int custId, int id, [FromBody] Stay stay) { if (ModelState.IsValid) { var oldStay = _ctx.Stays.Where(s => s.Id == id && s.Guest.Id == custId).FirstOrDefault(); if (oldStay == null) { return(NotFound()); } var room = _ctx.Rooms.Where(r => r.Id == stay.Room.Id).FirstOrDefault(); if (room == null) { return(NotFound()); } oldStay.Arrival = stay.Arrival; oldStay.Departure = stay.Departure; oldStay.Rate = stay.Rate; oldStay.Room = room; _ctx.SaveChanges(); return(Ok(oldStay)); } return(BadRequest()); }
private async Task CloseStay(ApplicationUser user, Stay stay) { stay.TimeOfExit = Time.Now(); _context.Update(stay); user.CurrentStayId = null; await _userInfoManager.Update(user); }
public IActionResult DeleteConfirmed(int ID) { // TODO: Add validation Stay stay = _stayService.FindByID(ID); _stayService.Remove(stay); return(RedirectToAction(nameof(Index))); }
public ActionResult DeleteConfirmed(int id) { Stay stay = db.Stays.Find(id); db.Stays.Remove(stay); db.SaveChanges(); return(RedirectToAction("Index")); }
static void PrintStay(Stay stay) { if (stay == null) { System.Console.WriteLine("No stay could be found for your trip"); return; } System.Console.WriteLine($"Staying for {stay.Nights} nights between {stay.StartDate.ToShortDateString()} to {stay.EndDate.ToShortDateString()}"); System.Console.WriteLine($"Your stay is at {stay.CheapestRate.Name} and has {stay.ApplicableOffers.Count} offers applied for a total cost of £{stay.Price}"); }
public void SaveStay(Stay stay) { try { ValidateStay(stay); _stayRepository.SaveStay(stay); } catch (InvalidOperationException e) { throw e; } }
public async Task <IActionResult> CheckOutGuest([FromBody] Stay guestStayDto) { try { await _guestStayService.CheckOutGuest(guestStayDto); } catch (ArgumentException e) { ModelState.AddModelError("Exception", e.Message); return(BadRequest(ModelState)); } return(Ok()); }
private static DateTime timeEndOfRisk(Stay stay1, Stay stay2) { DateTime TimeOfExit1 = stay1.TimeOfExit ?? Time.Now(); DateTime TimeOfExit2 = stay2.TimeOfExit ?? Time.Now(); if (TimeOfExit1 < TimeOfExit2) { return(TimeOfExit1); } return(TimeOfExit2); }
public void AnimalWithProperShouldBeAdded() { // Arrange var stayRepository = new Mock <IStayRepository>(); var stayService = new Mock <IStayService>(); Animal dog = new Animal() { Name = "Doggo", Birthdate = new DateTime(2018, 10, 18), Age = 2, EstimatedAge = 2, Description = "Good boi", AnimalType = AnimalType.Dog, Race = "Best Bois", Picture = "Goodboi.png", DateOfDeath = null, Castrated = true, ChildFriendly = ChildFriendly.Yes, ReasonGivenAway = "Too good a boi", }; Lodging coolLocation = new Lodging() { LodgingType = LodgingType.Group, MaxCapacity = 100, CurrentCapacity = 10, AnimalType = AnimalType.Cat, Stays = new List <Stay>() { }, }; Stay stay = new Stay() { Animal = dog, ArrivalDate = new DateTime(2019, 10, 18), AdoptionDate = null, CanBeAdopted = true, AdoptedBy = null, LodgingLocation = coolLocation, Comments = new List <Comment>(), Treatments = new List <Treatment>(), }; // Act stayService.Setup(_ => _.Add(stay)); // Assert IEnumerable <Stay> stays = stayRepository.Object.GetAll(); Assert.NotNull(stays); }
private void ValidateTreatment(Treatment treatment) { if (treatment.Stay == null) { throw new InvalidOperationException("Animal needs to be placed"); } else { // TODO: Cleanup if possible Animal animal = _animalRepository.FindByID(treatment.Stay.AnimalID); Stay stay = treatment.Stay; // Animal needs to be here and not adopted if (treatment.Date < stay.ArrivalDate || stay.AdoptionDate != null) { throw new InvalidOperationException("Animal needs to be at location"); } // Animal needs to be alive if (animal.DateOfDeath > DateTime.MinValue) { throw new InvalidOperationException("Animal must be alive in order to perform treatment"); } // RequiredAge needs to be lower then animal age if (treatment.RequiredAge > animal.Age) { throw new InvalidOperationException("Animal needs to be older to have this treatment"); } // Vaccination, operation, Chipping & Euthanasia need a description if (treatment.Description == null) { if (treatment.TreatmentType == TreatmentType.Chipping) { throw new InvalidOperationException("Chipping needs a description"); } if (treatment.TreatmentType == TreatmentType.Vaccination) { throw new InvalidOperationException("Vaccination needs a description"); } if (treatment.TreatmentType == TreatmentType.Operation) { throw new InvalidOperationException("Operation needs a description"); } if (treatment.TreatmentType == TreatmentType.Euthanasia) { throw new InvalidOperationException("Euthanasia needs a description"); } } } }
/// <summary> /// Finds related Stay object on bias of animal ID. /// </summary> /// <param name="ID">ID of Animal.</param> public Stay FindRelatedStay(int ID) { IEnumerable <Stay> AllStays = _stayRepository.GetAll(); // Usinq LINQ to find relatedStay var relatedStay = from Stay in AllStays where Stay.AnimalID == ID select Stay; // TODO: Clean this up with a cast? Stay stay = relatedStay.FirstOrDefault(); return(stay); }
private void OnNextButtonClick(object sender, EventArgs e) { var stay = new Stay { Country = _countrySpinner.SelectedItem.ToString(), City = _placeSpinner.SelectedItem.ToString(), Arrival = _arrival, Departure = _departure, IsCurrent = true }; DataEntryPoint.Instance.InsertStay(stay); }
public IActionResult Edit(int ID) { Treatment treatment = _treatmentService.FindByID(ID); Stay stay = _stayService.FindByID(treatment.StayID); var vm = new TreatmentViewModel() { Animal = _animalService.FindByID(stay.AnimalID), Treatment = treatment, Stay = stay }; return(View(vm)); }
// GET: Stays/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Stay stay = db.Stays.Find(id); if (stay == null) { return(HttpNotFound()); } return(View(stay)); }
public ActionResult StaysInfo(int id) { Stay stay = _context.Stays.Include(s => s.City) .Include(s => s.PropertyType) .Include(s => s.City.Country) .SingleOrDefault(c => c.Id == id); if (stay == null) { return(HttpNotFound()); } return(View(stay)); }
public async Task <Stay> Add(Stay stay) { var patient = await _db.Patients.FirstOrDefaultAsync(s => s.PatientId == stay.PatientId); if (patient == null) { throw new Exception($"Patient with id:{stay.PatientId} not found"); } await _db.Stays.AddAsync(stay); await SaveChanges(); return(stay); }
public ActionResult Post(string values) { var stay = new Stay(); JsonConvert.PopulateObject(values, stay); if (!TryValidateModel(stay)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ValidationErrorMessage)); } _repository.Insert(stay); return(new EmptyResult()); }
public Stay PlaceAnimal(Stay stay, Lodging lodge) { Lodging newLodge = _lodgingRepository.FindByID(lodge.ID); Stay newStay = new Stay(); try { if (stay.ID == null || stay.ID == 0) { newStay.LodgingLocationID = newLodge.ID; newStay.AnimalID = stay.AnimalID; newStay.ArrivalDate = stay.ArrivalDate; newStay.CanBeAdopted = stay.CanBeAdopted; ValidateStay(newStay); } else { newStay = _stayRepository.FindByID(stay.ID); } // If animal moved if (newStay.LodgingLocationID != newLodge.ID && newStay.LodgingLocationID != null) { newStay.LodgingLocationID = newLodge.ID; ValidateStay(newStay); Lodging currentLodge = _lodgingRepository.FindByID(newStay.LodgingLocationID); // Decrease capacity at old lodge currentLodge.CurrentCapacity = currentLodge.CurrentCapacity - 1; currentLodge.Stays.Remove(newStay); _lodgingRepository.SaveLodging(currentLodge); } SaveStay(newStay); // Increase capacity at new lodge newLodge.CurrentCapacity = newLodge.CurrentCapacity + 1; newLodge.Stays.Add(newStay); _lodgingRepository.SaveLodging(newLodge); return(newStay); } catch (InvalidOperationException e) { throw e; } }
public Potrait() { this.sprite = null; this.startPlacement = null; this.moveDirection = Vector2.zero; this.offset = 0; this.maxAlpha = 1; this.moveTime = 0; this.stayMethod = Stay.NONE; this.stayMoveSpeed = 1; this.stayDuration = 0; this.closeMethod = Closing.NONE; this.closeMoveSpeed = 1; this.closeSpeed = 1; this.isCoroutine = false; }
/// <summary> /// Get all related Comments on Animal ID bias /// </summary> /// <param name="AnimalID"></param> /// <returns></returns> public IEnumerable <Comment> GetRelatedComments(int AnimalID) { Stay stay = _stayService.FindRelatedStay(AnimalID); IEnumerable <Comment> Comments = _commentRepository.GetAll(); List <Comment> RelatedComments = new List <Comment>(); foreach (var comment in Comments) { if (comment.StayID == stay.ID) { RelatedComments.Add(comment); } } return(RelatedComments); }
public IActionResult Create(Stay stay) { if (ModelState.IsValid) { try { _stayService.Add(stay); } catch (InvalidOperationException e) { return(View(stay)); } return(RedirectToAction(nameof(Index))); } return(View(stay)); }
private async Task CreateStay(ApplicationUser user, int locationId, int serverId) { Stay newStay = new Stay { UserId = user.Id, LocationId = locationId, ServerId = serverId, TimeOfEntrance = Time.Now(), TimeOfExit = null }; _context.Add(newStay); _context.SaveChanges(); user.CurrentStayId = newStay.Id; await _userInfoManager.Update(user); }
public async Task <Stay> CheckOutGuest(Stay guestStayDto) { var guestStay = await _staysRepo.GetFirstOrDefault(s => s.Id == guestStayDto.Id); if (guestStay == null) { throw new System.ArgumentException("Room Number for this Building already exists", string.Empty); } guestStay.CheckOutDate = DateTime.Today; guestStay.CheckedOut = true; await _staysRepo.SaveAsync(); return(guestStay); }
public void Update() { for (int i = 0; i < endContacts.Count; ++i) { Contact contact = endContacts[i]; Fixture fixtureA = contact.FixtureA; Fixture fixtureB = contact.FixtureB; if (fixtureA == null || fixtureB == null) { continue; } if (fixtureA.Body.BodyType == BodyType.Static && fixtureB.Body.BodyType == BodyType.Static) { continue; } Component compA = fixtureA.Body.UserData; Component compB = fixtureB.Body.UserData; if (compA == null || compB == null) { continue; } if (fixtureA.IsSensor || fixtureB.IsSensor) { RemoveStay(compA.collider, compB.collider); compA.gameObject.OnTriggerExit(compB.collider); compB.gameObject.OnTriggerExit(compA.collider); } else { if (compA.rigidbody == null && compB.rigidbody == null) { continue; } if (compA.rigidbody != null && compB.rigidbody != null && compA.rigidbody.isKinematic && compB.rigidbody.isKinematic) { continue; } RemoveStay(compA.collider, compB.collider); Microsoft.Xna.Framework.Vector2 normal; FarseerPhysics.Common.FixedArray2<Microsoft.Xna.Framework.Vector2> points; contact.GetWorldManifold(out normal, out points); Collision coll = new Collision() { collider = compB.collider, relativeVelocity = ((compA.rigidbody != null) ? compA.rigidbody.velocity : Vector3.zero) - ((compB.rigidbody != null) ? compB.rigidbody.velocity : Vector3.zero), contacts = new ContactPoint[2] }; for (int j = 0; j < 2; j++) { coll.contacts[j].thisCollider = compA.collider; coll.contacts[j].otherCollider = compB.collider; coll.contacts[j].point = VectorConverter.Convert(points[j], compA.collider.to2dMode); coll.contacts[j].normal = VectorConverter.Convert(normal, compA.collider.to2dMode); } compA.gameObject.OnCollisionExit(coll); coll.SetColliders(compB.collider, compA.collider); compB.gameObject.OnCollisionExit(coll); } } for (int i = staying.Count - 1; i >= 0; i--) { if (staysToRemove[i] || staying[i].colliderToTriggerA.gameObject == null || staying[i].colliderToTriggerB.gameObject == null || !staying[i].colliderToTriggerA.gameObject.active || !staying[i].colliderToTriggerB.gameObject.active) { staysToRemove[i] = false; staying.RemoveAt(i); continue; } else if (!staying[i].collision) { staying[i].gameObjectA.OnTriggerStay(staying[i].colliderToTriggerA); staying[i].gameObjectB.OnTriggerStay(staying[i].colliderToTriggerB); } else { staying[i].gameObjectA.OnCollisionStay(staying[i].collisionBToA); staying[i].gameObjectB.OnCollisionStay(staying[i].collisionAToB); } } for (int i = 0; i < beginContacts.Count; ++i) { Contact contact = beginContacts[i]; Fixture fixtureA = contact.FixtureA; Fixture fixtureB = contact.FixtureB; if (fixtureA == null || fixtureB == null) { continue; } #if DEBUG if (DebugSettings.LogCollisions) { Debug.Log(string.Format("Collision Begin: {0} <-> {1}", fixtureA.Body, fixtureB.Body)); } #endif if (fixtureA.Body.BodyType == BodyType.Static && fixtureB.Body.BodyType == BodyType.Static) { continue; } Component compA = fixtureA.Body.UserData; Component compB = fixtureB.Body.UserData; if (compA == null || compB == null) { continue; } if (fixtureA.IsSensor || fixtureB.IsSensor) { staying.Add(new Stay(compB.collider, compA.collider, compA.gameObject, compB.gameObject )); compA.gameObject.OnTriggerEnter(compB.collider); compB.gameObject.OnTriggerEnter(compA.collider); } else { if (compA.rigidbody == null && compB.rigidbody == null) { continue; } if (compA.rigidbody != null && compB.rigidbody != null && compA.rigidbody.isKinematic && compB.rigidbody.isKinematic) { continue; } Microsoft.Xna.Framework.Vector2 normal; FarseerPhysics.Common.FixedArray2<Microsoft.Xna.Framework.Vector2> points; contact.GetWorldManifold(out normal, out points); Collision collisionBToA = new Collision() { collider = compB.collider, relativeVelocity = ((compA.rigidbody != null) ? compA.rigidbody.velocity : Vector3.zero) - ((compB.rigidbody != null) ? compB.rigidbody.velocity : Vector3.zero), contacts = new ContactPoint[contact.Manifold.PointCount] }; Collision collisionAToB = new Collision() { collider = compA.collider, relativeVelocity = ((compB.rigidbody != null) ? compB.rigidbody.velocity : Vector3.zero) - ((compA.rigidbody != null) ? compA.rigidbody.velocity : Vector3.zero), contacts = new ContactPoint[contact.Manifold.PointCount] }; for (int j = 0; j < collisionBToA.contacts.Length; j++) { collisionBToA.contacts[j].thisCollider = compB.collider; collisionBToA.contacts[j].otherCollider = compA.collider; collisionBToA.contacts[j].point = VectorConverter.Convert(points[j], compB.collider.to2dMode); collisionBToA.contacts[j].normal = VectorConverter.Convert(-normal, compB.collider.to2dMode); collisionAToB.contacts[j].thisCollider = compA.collider; collisionAToB.contacts[j].otherCollider = compB.collider; collisionAToB.contacts[j].point = VectorConverter.Convert(points[j], compA.collider.to2dMode); collisionAToB.contacts[j].normal = VectorConverter.Convert(normal, compA.collider.to2dMode); } Stay s = new Stay(collisionAToB, collisionBToA, compA.gameObject, compB.gameObject); staying.Add(s); s.gameObjectA.OnCollisionEnter(s.collisionBToA); s.gameObjectB.OnCollisionEnter(s.collisionAToB); } } beginContacts.Clear(); endContacts.Clear(); }