// GET: api/Apatment //IEnumerable<Appartment> Get() public string Get() { Appartment P = new Appartment("New", "New", 2); string output = P.GetAp(); return(output); }
// PUT: api/Apatment/5CMDnewtitle public string Put(string Input) { string[] Data = Input.Split(new string[] { "CMD" }, StringSplitOptions.None); Appartment temp = new Appartment("temp", "temp", 0); return(temp.Update(Convert.ToInt32(Data[0]), Data[1])); }
static void Main(string[] args) { RealEstateAgent immo = new RealEstateAgent(); Appartment app1 = new Appartment("Appartementstraat 10", 1, 180000); Appartment app2 = new Appartment("Appartementstraat 15", 3, 320000); House house1 = new House("Huisstraat 10", 1, 220000); House house2 = new House("Huisstraat 31", 3, 380000); immo.AddAppartment(app1); immo.AddAppartment(app2); immo.AddHouse(house1); immo.AddHouse(house2); Console.WriteLine("All appartments for sale:"); immo.ShowAllAppartments(); Console.WriteLine("----------------"); Console.WriteLine("All houses for sale:"); immo.ShowAllHouses(); Console.ReadLine(); }
public async Task <IHttpActionResult> PostAppartment(Appartment appartment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Appartments.Add(appartment); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (AppartmentExists(appartment.AppartmentNo)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = appartment.AppartmentNo }, appartment)); }
public async Task <IHttpActionResult> PutAppartment(int id, Appartment appartment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != appartment.AppartmentNo) { return(BadRequest()); } db.Entry(appartment).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AppartmentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <ActionResult <Appartment> > PostAppartment(Appartment appartment) { _context.Appartments.Add(appartment); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAppartment", new { id = appartment.AppartmentId }, appartment)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,Price,Owner,Photo,PhotoPath")] Appartment appartment) { if (id != appartment.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(appartment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AppartmentExists(appartment.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(appartment)); }
//CRUD of Appartment public List <Appartment> GetAppartment() { string sqlString = @" SELECT [ID], [AppartmentNo], [Area] FROM [Appartment] "; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(sqlString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <Appartment> appartments = new List <Appartment>(); while (reader.Read()) { Appartment appartment = new Appartment { ID = int.Parse(reader["ID"].ToString()), AppartmentNo = int.Parse(reader["AppartmentNo"].ToString()), Area = int.Parse(reader["Area"].ToString()), }; appartment.Humans = new HumanDbCommands().GetHumansByApartment(appartment.ID); appartments.Add(appartment); } return(appartments); } }
public async Task <IActionResult> PutAppartment(Guid id, Appartment appartment) { if (id != appartment.AppartmentId) { return(BadRequest()); } _context.Entry(appartment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AppartmentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create(AppartmentViewModel appartment) { if (appartment.Photo != null) { BlobContainerClient containerClient = _blobService.GetBlobContainerClient("home"); Stream stream = appartment.Photo.OpenReadStream(); string fileName = $"{Guid.NewGuid().ToString()}{appartment.Photo.FileName}"; BlobContentInfo blobContent = await containerClient.UploadBlobAsync(fileName, stream); BlobClient blobClient = containerClient.GetBlobClient(fileName); string url = blobClient.Uri.AbsoluteUri; Appartment newAppart = new Appartment(); newAppart.Title = appartment.Title; newAppart.Description = appartment.Description; newAppart.Owner = appartment.Owner; newAppart.Price = appartment.Price; newAppart.Photo = fileName; newAppart.PhotoPath = url; _context.Add(newAppart); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(appartment)); }
public async System.Threading.Tasks.Task <ActionResult> Index() { mBuilding = TempData["myBuilding"] as Building; TempData.Keep("myBuilding"); var query = ParseObject.GetQuery("Building").WhereEqualTo("objectId", mBuilding.id); IEnumerable <ParseObject> results = await query.FindAsync(); foreach (ParseObject userData in results) { var appQuery = ParseObject.GetQuery("Appartment").WhereEqualTo("Building", userData); IEnumerable <ParseObject> appResults = await appQuery.FindAsync(); mAppList = new AppartmentsList(); mAppList.appList = new List <Appartment>(); Appartment tempApp; foreach (ParseObject pObj in appResults) { tempApp = new Appartment(); tempApp.name = pObj.Get <string>("Name"); tempApp.objId = pObj.ObjectId; tempApp.settlement = pObj.Get <float>("Settlement"); mAppList.appList.Add(tempApp); } mAppList.size = mAppList.appList.Count; } return(View(mAppList)); }
////search function by AppartmentId //public static Appartment SearchRecord(int searchId) //{ // Appartment app = new Appartment(); // SqlConnection conn = UtilityDB.ConnectDB(); // SqlCommand cmd = new SqlCommand(); // cmd.Connection = conn; // cmd.CommandText = "Select * From Appartments where AppartmentId = @AppartmentId "; // cmd.Parameters.AddWithValue("@AppartmentId", searchId); // SqlDataReader reader = cmd.ExecuteReader(); // if (reader.Read()) // { // app.AppartmentId = Convert.ToInt32(reader["EmployeeId"]); // app.NumberOfRoom = Convert.ToInt32(reader["NumberOfRoom"]); // app.NumberOfBath = Convert.ToInt32(reader["NumberOfBath"]); // app.NumberOfParking = Convert.ToInt32(reader["NumberOfParking"]); // app.FloorNum = Convert.ToInt32(reader["FloorNum"]); // app.PricePerMonth = Convert.ToInt32(reader["PricePerMonth"]); // app.Description = Convert.ToString(reader["Description"]); // app.RentStatus = Convert.ToString(reader["RentStatus"]); // app.BuildingId = Convert.ToInt32(reader["BuildingId"]); // } // else // { // app = null; // } // conn.Close(); // return app; //} //search more than one record by Int public static List <Appartment> SearchRecords(SqlDataReader reader) { List <Appartment> ListApp = new List <Appartment>(); Appartment app; if (reader.HasRows) { while (reader.Read()) { app = new Appartment(); app.AppartmentId = Convert.ToInt32(reader["AppartmentId"]); app.NumberOfRoom = Convert.ToInt32(reader["NumberOfRoom"]); app.NumberOfBath = Convert.ToInt32(reader["NumberOfBath"]); app.NumberOfParking = Convert.ToInt32(reader["NumberOfParking"]); app.FloorNum = Convert.ToInt32(reader["FloorNum"]); app.PricePerMonth = Convert.ToInt32(reader["PricePerMonth"]); app.Description = Convert.ToString(reader["Description"]); app.RentStatus = Convert.ToString(reader["RentStatus"]); app.BuildingId = Convert.ToInt32(reader["BuildingId"]); ListApp.Add(app); } } else { ListApp = null; } return(ListApp); }
public async Task AppartmentCreate_Invalid() { // Setup AppartmentDTO testApt = new AppartmentDTO() { address = new AddressDTO() { buildingNo = "142A", street = "Test Road" } }; Appartment apt = _mapper.Map <Appartment>(testApt); if (!new AppConfigration().IsRealMongoDbUsed()) { _mockRepo.Setup(repo => repo.CreateAppartment(apt)) .Verifiable(); } // Act var result = await _controller.Post(testApt); // Assert var actionResult = Assert.IsType <ActionResult <AppartmentDTO> >(result); var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(actionResult.Result); var returnValue = Assert.IsType <AppartmentDTO>(badRequestObjectResult.Value); }
public IActionResult Edit(int id) { List <Appartment> appartments = new AppartmentDbCommands().GetAppartment(); Appartment appartment = appartments.First(a => a.ID == id); return(View(appartment)); }
public async Task <ActionResult> Add() { int pos = Int32.Parse(Request.Form["iden"]); float addAmountSt = float.Parse(Request.Form["addAmount"], CultureInfo.InvariantCulture.NumberFormat); float negAmountSt = float.Parse(Request.Form["negAmount"], CultureInfo.InvariantCulture.NumberFormat); mBuilding = TempData["myBuilding"] as Building; TempData.Keep("myBuilding"); var query = ParseObject.GetQuery("Building").WhereEqualTo("objectId", mBuilding.id); IEnumerable <ParseObject> results = await query.FindAsync(); foreach (ParseObject userData in results) { var appQuery = ParseObject.GetQuery("Appartment").WhereEqualTo("Building", userData); IEnumerable <ParseObject> appResults = await appQuery.FindAsync(); mAppList = new AppartmentsList(); mAppList.appList = new List <Appartment>(); Appartment tempApp; foreach (ParseObject pObj in appResults) { tempApp = new Appartment(); tempApp.name = pObj.Get <string>("Name"); tempApp.objId = pObj.ObjectId; tempApp.settlement = pObj.Get <float>("Settlement"); mAppList.appList.Add(tempApp); } mAppList.size = mAppList.appList.Count; var queryApp = ParseObject.GetQuery("Appartment").WhereEqualTo("objectId", mAppList.appList[pos].objId); IEnumerable <ParseObject> resultsApp = await queryApp.FindAsync(); foreach (ParseObject appObj in resultsApp) { if (negAmountSt == 0) { appObj["Settlement"] = appObj.Get <float>("Settlement") + addAmountSt; } else { appObj["Settlement"] = appObj.Get <float>("Settlement") - negAmountSt; } await appObj.SaveAsync(); } } return(RedirectToAction("Index", "AdminNavigation")); }
protected void btnSubmitFlat_Click(object sender, EventArgs e) { Appartment CurrentAppartment = CreateAppartmentObject(); PropertyData.UploadAd_Appartment(CurrentAppartment); UploadImages(); Response.Redirect("Index.aspx"); }
public ActionResult DeleteConfirmed(int id) { Appartment appartment = db.Appartments.Find(id); db.Appartments.Remove(appartment); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <bool> UpdateAppartment(Appartment apt) { FilterDefinition <Appartment> filter = Builders <Appartment> .Filter.Eq(_apt => _apt.id, apt.id); ReplaceOneResult res = await _context.Appartments.ReplaceOneAsync(filter : filter, replacement : apt); return(res.IsAcknowledged && res.ModifiedCount > 0); }
public async Task <ActionResult> DeleteConfirmed(int id) { Appartment appartment = await db.Appartments.FindAsync(id); db.Appartments.Remove(appartment); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
// POST: api/Apatment/TitleCMDAddressCMDNbrofRooms // CMD is used for string split public string Post(string Input) { string[] Data = Input.Split(new string[] { "CMD" }, StringSplitOptions.None); Appartment P = new Appartment(Data[0], Data[1], Convert.ToInt32(Data[2])); P.Add(); return("New Appartment Id=" + P.Id + " Was Created"); }
/// <summary> /// Удаление Квартиры по Id /// </summary> /// <param name="id">Id квартиры</param> /// <returns></returns> public async Task Delete(int id) { Appartment appartment = await _appartmentContext.Appartments.FindAsync(id); if (appartment != null) { _appartmentContext.Appartments.Remove(appartment); } }
private void DeleteAppartment() { if (this.selectedAppartment != null) { context.DeleteAppartment(selectedAppartment.AppartmentId); context.DataContext.SaveChanges(); Appartments.Remove(selectedAppartment); selectedAppartment = null; } }
public async Task <IHttpActionResult> GetAppartment(int id) { Appartment appartment = await db.Appartments.FindAsync(id); if (appartment == null) { return(NotFound()); } return(Ok(appartment)); }
public ActionResult Edit([Bind(Include = "AppartmentId,NumberOfRoom,NumberOfBath,NumberOfParking,FloorNum,PricePerMonth,Description,RentStatus,BuildingId")] Appartment appartment) { if (ModelState.IsValid) { db.Entry(appartment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BuildingId = new SelectList(db.Buildings, "BuildingId", "Address", appartment.BuildingId); return(View(appartment)); }
public void InsertAppartment(Appartment appartment) { string query = "INSERT INTO dbo.Appartment(AppartmentNo,Area) VALUES(@AppartmentNo,@Area)"; using (SqlConnection cn = new SqlConnection(connectionString)) { cn.Open(); cn.Execute(query, appartment); cn.Close(); } }
public void UpdateAppartment(int oldID, Appartment appartment) { string query = "UPDATE Appartament SET AppartmentNo = @NewAppartmentNo, Are = @Area, HumansName = @HumansName BirthDate = @BirthDate WHERE ID = @oldID"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); connection.Execute(query, appartment); } }
private void GetAppartmentList() { using (var api = new BusinessContext()) { Appartments.Clear(); context.GetAppartmentList(); selectedAppartment = null; foreach (var appartment in context.GetAppartmentList()) { Appartments.Add(appartment); } } }
public async Task <IHttpActionResult> DeleteAppartment(int id) { Appartment appartment = await db.Appartments.FindAsync(id); if (appartment == null) { return(NotFound()); } db.Appartments.Remove(appartment); await db.SaveChangesAsync(); return(Ok(appartment)); }
public ActionResult Edit([Bind(Include = "Apt_id,Build_id,Manager_id,Tenant_id,Owner_id,Description")] Appartment appartment) { if (ModelState.IsValid) { db.Entry(appartment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Build_id = new SelectList(db.Buildings, "Build_id", "Description", appartment.Build_id); ViewBag.Tenant_id = new SelectList(db.Persons, "P_id", "FirstName", appartment.Tenant_id); ViewBag.Manager_id = new SelectList(db.Persons, "P_id", "FirstName", appartment.Manager_id); ViewBag.Owner_id = new SelectList(db.Persons, "P_id", "FirstName", appartment.Owner_id); return(View(appartment)); }
// GET: Appartments/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Appartment appartment = db.Appartments.Find(id); if (appartment == null) { return(HttpNotFound()); } return(View(appartment)); }
public static BaseHouse Create(RHP.Common.Enums.HouseType houseType) { BaseHouse baseHouse; switch (houseType) { case RHP.Common.Enums.HouseType.Dorms: baseHouse = new Dorm(); break; case RHP.Common.Enums.HouseType.Appartment: baseHouse = new Appartment(); break; case RHP.Common.Enums.HouseType.Condo: baseHouse = new Condo(); break; case RHP.Common.Enums.HouseType.FamilyHousing: baseHouse = new FamilyHousing(); break; case RHP.Common.Enums.HouseType.House: baseHouse = new OnCampusHouse(); break; case RHP.Common.Enums.HouseType.OffCampusAppartment: baseHouse = new OffCampusAppartment(); break; case RHP.Common.Enums.HouseType.OffCampusCondo: baseHouse = new OffCampusCondo(); break; case RHP.Common.Enums.HouseType.TownHome: baseHouse = new TownHome(); break; case RHP.Common.Enums.HouseType.OffCampusHouse: baseHouse = new OffCampusHouse(); break; default: baseHouse = new Dorm(); break; } return baseHouse; }