public async Task <IActionResult> PutMotelNV(int id, Motel motel) { if (id != motel.Id) { return(BadRequest()); } _context.Entry(motel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MotelExists(id)) { return(NotFound()); } else { throw; } } return(CreatedAtAction("GetMotel", new { id = motel.Id }, motel)); }
static void Main(string[] args) { Motel BatesMotel = new Motel(); BatesMotel.Run(); Console.ReadLine(); }
/// <summary> /// Gets a test motel for automated tests. /// </summary> /// <returns></returns> public Models.Motel GetMotel() { var result = new Motel(); //generate all rooms. for (int currentLevel = 1; currentLevel <= result.MaxLevelCount; currentLevel++) { for (int currentRoom = 0; currentRoom < result.MaxRoomCountPerLevel; currentRoom++) { var r = new Room(); r.Level = currentLevel; r.RoomNumber = (currentLevel * 100) + currentRoom; //Get a random number between 1 and 3. used a helper method because this is being created in a //tight (ie fast) loop and the Math.Random class doesn't like that. r.BedCount = StaticRandom.Instance.Next(1, 4); result.Rooms.Add(r); } } //TODO: generate Guests //TODO: generate Reservations return(result); }
// GET: Motel public ActionResult ViewMotel() { SqlConnection con = new SqlConnection(); SqlCommand command = new SqlCommand(); SqlDataReader dr; List <Motel> MotelList = new List <Motel>(); con = DBServices.openConnection(); command.Connection = con; command.CommandText = "SELECT ID,NAME,Address,Information,Longitude,Latitude FROM Motel WHERE UserID=@userID "; command.Parameters.Add("@userID", SqlDbType.NVarChar, 50).Value = ((Account)Session["USER"]).UserId; dr = command.ExecuteReader(); while (dr.Read()) { Motel tmp = new Motel(); tmp.ID = dr.GetString(0); tmp.Name = dr.GetString(1); tmp.Address = dr.GetString(2); tmp.Information = dr.GetString(3); tmp.Longitude = float.Parse(dr.GetDouble(4).ToString()); tmp.Latitude = float.Parse(dr.GetDouble(5).ToString()); MotelList.Add(tmp); } ViewBag.MOTELLIST = MotelList; return(View()); }
/// <summary> /// Gets all rooms in the Motel. /// </summary> /// <returns></returns> public List <Room> GetAllRooms() { //READER's NOTE: //Normally this would be fetched from the Database but since I do not have that, I'll just hard-code it. var result = new Motel(); //generate all rooms. for (int currentLevel = 1; currentLevel <= result.MaxLevelCount; currentLevel++) { for (int currentRoom = 0; currentRoom < result.MaxRoomCountPerLevel; currentRoom++) { var r = new Room(); r.Level = currentLevel; r.RoomNumber = (currentLevel * 100) + currentRoom; //Get a random number between 1 and 3. //Used a helper method because this is being created in a //tight (ie fast) loop and the Math.Random class generates random numbers based on millisecond ticks. r.BedCount = StaticRandom.Instance.Next(1, 4); result.Rooms.Add(r); } } return(result.Rooms); }
public async Task <ActionResult <IEnumerable <Image> > > PostImage(Motel motel) { var image = motel.Images.ToList(); _context.Images.AddRange(motel.Images); await _context.SaveChangesAsync(); return(image); }
/*public ActionResult GetAllMotel() * { * List<Motel> list = new List<Motel>(); * SqlConnection con = DBServices.openConnection(); * string query = "SELECT ID, Name, UserID, Address, Information, Longitude, Latitude" + * " FROM tbl_MotelRoom"; * SqlCommand command = new SqlCommand(query, con); * SqlDataReader data = command.ExecuteReader(); * while(data.Read()) * { * string ID = "", Name = "", UserID = "", Address = "", Information = ""; * float Longitude; * float Latitude; * ID = data.GetString(0); * Name = data.GetString(1); * UserID = data.GetString(2); * if (data["Address"] != DBNull.Value) * { * Address = data.GetString(3); * } * if (data["Information"] != DBNull.Value) * { * Information = data.GetString(4); * } * Longitude = data.GetFloat(5); * Latitude = data.GetFloat(6); * Motel motel = new Motel(ID, Name, UserID, Address, Information, Longitude, Latitude); * list.Add(motel); * } * return Json(list, JsonRequestBehavior.AllowGet); * }*/ /*public ActionResult GetMotelPaging(int previous) * { * List<Motel> list = new List<Motel>(); * int next = previous + 5; * SqlConnection con = DBServices.openConnection(); * string query = "SELECT TOP " + next + * " ID, Name, UserID, Address, Information, Longitude, Latitude" + * " FROM tbl_MotelRoom " + * "EXCEPT SELECT TOP " + previous + * " ID, Name, UserID, Address, Information, Longitude, Latitude" + * " FROM tbl_MotelRoom"; * SqlCommand command = new SqlCommand(query, con); * //command.Parameters.Add("@NEXT", SqlDbType.Int).Value = next; * //command.Parameters.Add("@PREVIOUS", SqlDbType.Int).Value = previous; * SqlDataReader data = command.ExecuteReader(); * while (data.Read()) * { * string ID = "", Name = "", UserID = "", Address = "", Information = ""; * float Longitude; * float Latitude; * ID = data.GetString(0); * Name = data.GetString(1); * UserID = data.GetString(2); * if (data["Address"] != DBNull.Value) * { * Address = data.GetString(3); * } * if (data["Information"] != DBNull.Value) * { * Information = data.GetString(4); * } * Longitude = data.GetFloat(5); * Latitude = data.GetFloat(6); * Motel motel = new Motel(ID, Name, UserID, Address, Information, Longitude, Latitude); * list.Add(motel); * } * return Json(list, JsonRequestBehavior.AllowGet); * }*/ public ActionResult GetMotelByPosition(float lat, float lng) { List <Motel> list = new List <Motel>(); SqlConnection con = DBServices.openConnection(); string query = "SELECT ID, Name, UserID, Address, Information, Longitude, Latitude, " + "Internet, Electric, Water, ParkingPlace " + "FROM Motel WHERE SQRT(SQUARE(@LNG - Longitude) + SQUARE(@LAT - Latitude)) <= 0.0117"; SqlCommand command = new SqlCommand(query, con); command.Parameters.Add("@LNG", SqlDbType.Float).Value = lng; command.Parameters.Add("@LAT", SqlDbType.Float).Value = lat; SqlDataReader data = command.ExecuteReader(); while (data.Read()) { string ID = "", Name = "", UserID = "", Address = "", Information = ""; string Internet = "", Electric = "", Water = "", ParkingPlace = ""; float Longitude; float Latitude; ID = data.GetString(0); Name = data.GetString(1); UserID = data.GetString(2); if (data["Address"] != DBNull.Value) { Address = data.GetString(3); } if (data["Information"] != DBNull.Value) { Information = data.GetString(4); } if (data["Internet"] != DBNull.Value) { Internet = data.GetString(7); } if (data["Electric"] != DBNull.Value) { Electric = data.GetString(8); } if (data["Water"] != DBNull.Value) { Water = data.GetString(9); } if (data["ParkingPlace"] != DBNull.Value) { ParkingPlace = data.GetString(10); } Longitude = float.Parse(data["Longitude"].ToString()); Latitude = float.Parse(data["Latitude"].ToString()); Motel motel = new Motel(ID, Name, UserID, Address, Information, Longitude, Latitude, Internet, Electric, Water, ParkingPlace); list.Add(motel); } return(Json(list, JsonRequestBehavior.AllowGet)); }
public void CheckLowRoomNumber() { //arrange double vRoomsNo = 1; int vFloorsNo = 1; Motel expected = null; //act Motel vTestMotel = new Motel(vRoomsNo, vFloorsNo); //assert Assert.AreEqual(expected, vTestMotel, "Unable to make Motel"); }
public static Motel BuildMotel() { var motel = new Motel { Rooms = new List <Room> { new Room { Features = new List <RoomFeature> { new RoomFeature(FeatureNames.OneBed), }, RoomName = "1BedA", Status = Statuses.Empty, }, new Room { Features = new List <RoomFeature> { new RoomFeature(FeatureNames.OneBed), }, RoomName = "1BedB", Status = Statuses.NeedsCleaning, }, new Room { Features = new List <RoomFeature> { new RoomFeature(FeatureNames.OneBed), new RoomFeature(FeatureNames.TwoBeds), }, RoomName = "2BedA", Status = Statuses.Empty, }, new Room { Features = new List <RoomFeature> { new RoomFeature(FeatureNames.OneBed), new RoomFeature(FeatureNames.TwoBeds), new RoomFeature(FeatureNames.ThreeBeds), new RoomFeature(FeatureNames.Accessible), }, RoomName = "3BedAndAccessible", Status = Statuses.Empty, }, } }; return(motel); }
public void EngineRefillOutOfStation() { //arrange Motel vTestMotel = new Motel(16, 1); Game vTestGame = new Game(vTestMotel, GameSpeed.AVERAGE); bool expected = false; //act vTestGame.MoveEngine(vTestMotel.GetRooms().ElementAt(1)); vTestGame.EngineRefill(); //assert Assert.AreEqual(expected, vTestGame.TestEngine().CoolantTest(), "cant refill"); }
public async Task <IActionResult> PutMotelExtend(int id, Motel motel) { if (id != motel.Id) { return(BadRequest()); } DateTime daydue = DateTime.Now; string[] xet = motel.Time.Split(" "); if (xet[1].Equals("Tháng")) { motel.DateDue = daydue.AddMonths(int.Parse(xet[0])); } else if (xet[1].Equals("Ngày")) { TimeSpan aInterval = new System.TimeSpan(int.Parse(xet[0]), 0, 0, 0); motel.DateDue = daydue.Add(aInterval); } else if (xet[1].Equals("Tuần")) { int day = int.Parse(xet[0]) * 7; motel.DateDue = daydue.AddDays(day); } motel.DateUpdate = DateTime.Now; motel.Status = "2"; motel.Verify = false; _context.Entry(motel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MotelExists(id)) { return(NotFound()); } else { throw; } } return(CreatedAtAction("GetMotel", new { id = motel.Id }, motel)); }
public void GoToInvalidRoom() { //arrange Motel vTestMotel = new Motel(16, 1); Game vTestGame = new Game(vTestMotel, GameSpeed.AVERAGE); Location expected = vTestMotel.GetRooms().ElementAt(0); Room vFailRoom = new Room(1000); //act vTestGame.MoveEngine(vFailRoom); //assert Assert.AreEqual(expected, vFailRoom, "move unsuccesful"); }
public async Task <ActionResult <Motel> > PostMotel(Motel motel) { DateTime daydue = DateTime.Now; string[] xet = motel.Time.Split(" "); if (xet[1].Equals("Tháng")) { motel.DateDue = daydue.AddMonths(int.Parse(xet[0])); } else if (xet[1].Equals("Ngày")) { TimeSpan aInterval = new System.TimeSpan(int.Parse(xet[0]), 0, 0, 0); motel.DateDue = daydue.Add(aInterval); } else if (xet[1].Equals("Tuần")) { int day = int.Parse(xet[0]) * 7; motel.DateDue = daydue.AddDays(day); } motel.DateUpdate = DateTime.Now; motel.Verify = false; _context.Motels.Add(motel); await _context.SaveChangesAsync(); int id = motel.Id; _context.Details.Add(motel.Detail); if (motel.Images.Count == 0) { ///return NotFound(); return(CreatedAtAction("GetMotel", new { id = motel.Id }, motel)); } else { for (int i = 0; i < motel.Images.Count; i++) { motel.Images.ElementAt(i).MotelId = id; } _context.Images.AddRange(motel.Images); } return(CreatedAtAction("GetMotel", new { id = motel.Id }, motel)); }
public async void GetDistance(Motel motel) { try { //Get the current user's position var userLocation = await Geolocation.GetLastKnownLocationAsync(); var fromLocation = new Location(userLocation.Latitude, userLocation.Longitude); var toLocation = new Location(motel.Latitude, motel.Longitude); //Calculate distance double distance = fromLocation.CalculateDistance(toLocation, DistanceUnits.Kilometers); Distance = $"{Math.Round(distance)} KMs"; } catch (Exception ex) { // Handle exception when the distance is unknown } }
public ActionResult InsertNewMotel(Motel dto) { SqlConnection con = new SqlConnection(); SqlCommand command = new SqlCommand(); if (!ModelState.IsValid) { Debug.WriteLine("That Bai. sai du lieu"); ViewBag.ID = getNewMotelID(); return(View("InsertMotel")); } ViewBag.ID = dto.ID; con = DBServices.openConnection(); command.Connection = con; command.CommandText = "INSERT INTO Motel(ID,Name,UserID,Address,Information,Longitude,Latitude,Internet,Electric,Water,ParkingPlace)" + "VALUES (@Id,@Name,@UserID,@Address,@Inforation,@Longitude,@Latitude,@Internet,@Electric,@Water,@ParkingPlace)"; command.Parameters.Add("@Id", SqlDbType.VarChar, 10).Value = dto.ID; command.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = dto.Name; command.Parameters.Add("@UserID", SqlDbType.NVarChar, 50).Value = dto.UserId; command.Parameters.Add("@Address", SqlDbType.NVarChar, 200).Value = dto.Address; command.Parameters.Add("@Inforation", SqlDbType.NVarChar, 500).Value = dto.Information + ""; command.Parameters.Add("@Longitude", SqlDbType.Float).Value = dto.Longitude; command.Parameters.Add("@Latitude", SqlDbType.Float).Value = dto.Latitude; command.Parameters.Add("@Internet", SqlDbType.NVarChar, 100).Value = dto.Internet; command.Parameters.Add("@Electric", SqlDbType.NVarChar, 100).Value = dto.Electric; command.Parameters.Add("@Water", SqlDbType.NVarChar, 100).Value = dto.Water; command.Parameters.Add("@ParkingPlace", SqlDbType.NVarChar, 100).Value = dto.ParkingPlace; int rs = command.ExecuteNonQuery(); if (rs > 0) { con.Close(); Debug.WriteLine("Thanh cong"); return(RedirectToAction("ViewMotel")); } con.Close(); Debug.WriteLine("That Bai"); ViewBag.ID = getNewMotelID(); return(View("InsertMotel")); }
static void RunMotel() { Motel motel = new Motel(); motel.RunMotel(); }
static void TestMotel() { Motel batesMotel = new Motel(); batesMotel.RunMotel(); }