/// <summary> /// Method for getting estate obj from database /// </summary> /// <param name="objId">Object id in database</param> /// <returns>EstateObject with all filled fields</returns> public EstateObject GetEstateObject(int objId) { EstateObject estate = new EstateObject(); Connect(@"C:\BD\RealtorEstateAgancy.sqlite"); connection.Open(); command = new SQLiteCommand("select dealType, locality, address, area, roomNumber, floor, maxFloor," + "material, price, description, avitoId from EstateObject where id = " + objId + ";", connection); SQLiteDataReader dealTypeReader = command.ExecuteReader(); while (dealTypeReader.Read()) { estate.dealType = dealTypeReader.GetString(0); estate.locality = dealTypeReader.GetString(1); estate.address = dealTypeReader.GetString(2); estate.area = dealTypeReader.GetString(3); estate.roomNumber = dealTypeReader.GetString(4); estate.floor = dealTypeReader.GetString(5); estate.maxFloor = dealTypeReader.GetString(6); estate.material = dealTypeReader.GetString(7); estate.price = dealTypeReader.GetString(8); estate.description = dealTypeReader.GetString(9); estate.avitoId = dealTypeReader.GetString(10); } dealTypeReader.Close(); connection.Close(); return(estate); }
private string GetAvitoId() { SQLitekurs.SQLite db = new SQLitekurs.SQLite(); int objectId = Convert.ToInt32(id.Invoke()); EstateObject estate = db.GetEstateObject(objectId); return(estate.avitoId); }
public async Task <ActionResult> DeleteEstateObject(int id) { Agency db = new Agency(); EstateObject result = db.EstateObjects.FirstOrDefault(f => f.Id == id); EstateObjectViewModel model = await _estateObjectService.Model(result); return(View(model)); }
/// <summary> /// The one method to put different types of estate objects into caches. <br/> /// Key is chosen automatically. <br/> /// Method checks referential integrity on: <br/> /// EstateObject.SellerID - Person.key. <br/> /// EstateObject.LocationID - Location.key. /// </summary> /// <param name="value">Estate object to put into cache.</param> public static void PutEstateObject (EstateObject value) { using (var tx = Client.GetTransactions().TxStart()) { // Error if Person with key = value.SellerID is not found. if (!(PersonCache.ContainsKey(value.SellerID))) { tx.Commit(); throw new ReferentialException ("Can not put new entry into EstateObject cache.") { Operation = "put", TableName = "EstateObject", FieldName = "SellerID", ReadableMessage = $"Can not put new entry into EstateObject cache because Person with key {value.SellerID} does not exist." }; } // Error if Location not found. if (!(LocationCache.ContainsKey(value.LocationID))) { tx.Commit(); throw new ReferentialException ("Can not put new entry into EstateObject cache.") { Operation = "put", TableName = "EstateObject", FieldName = "LocationID", ReadableMessage = $"Can not put new entry into EstateObject cache because Location with key {value.LocationID} does not exist." }; } // Normal operation. int key = LastUsedKeys.Get("estateobject"); switch ((char)value.Variant) { case 'o': ObjectCache.Put (key, value); break; case 'h': HouseCache.Put (key, (House)value); break; case 'f': FlatCache.Put (key, (Flat)value); break; case 'l': LandplotCache.Put (key, (Landplot)value); break; default: break; } LastUsedKeys.Put("estateobject", key+1); tx.Commit(); } }
public async Task <ActionResult> UpdateEstateObject(int id) { Agency db = new Agency(); EstateObject eo = await db.EstateObjects.FirstOrDefaultAsync(f => f.Id == id); EstateObjectViewModel model = await _estateObjectService.Model(eo); return(View(model)); }
public async Task <ActionResult> DeleteTrade(int id) { Agency db = new Agency(); EstateObject eo = await db.EstateObjects.FirstOrDefaultAsync(f => f.Id == id); TradeRequestViewModel model = await tradeService.Model(eo); return(View(model)); }
private void FullDescriptionForm_Load(object sender, EventArgs e) { SQLitekurs.SQLite db = new SQLitekurs.SQLite(); int objectId = Convert.ToInt32(id.Invoke()); EstateObject estate = db.GetEstateObject(objectId); dealTypeLabel.Text = estate.dealType; localityLabel.Text = estate.locality; addressLabel.Text = estate.address; areaLabel.Text = estate.area; roomNumberLabel.Text = estate.roomNumber; floorLabel.Text = estate.floor + "/" + estate.maxFloor; materialLabel.Text = estate.material; priceLabel.Text = estate.price; descriptionRTB.Text = estate.description; }
public void Edit(EstateObject estate, int objId) { connection.Open(); command = new SQLiteCommand(connection); command.CommandText = @"UPDATE EstateObject SET " + "dealType = '" + estate.dealType + "'," + "locality = '" + estate.locality + "'," + "address = '" + estate.address + "'," + "area = '" + estate.area + "'," + "roomNumber = '" + estate.roomNumber + "'," + "floor = '" + estate.floor + "'," + "maxFloor = '" + estate.maxFloor + "'," + "material = '" + estate.material + "'," + "price = '" + estate.price + "'," + "description = '" + estate.description + "' " + "where id =" + objId; command.ExecuteNonQuery(); connection.Close(); }
private void addBtn_Click(object sender, EventArgs e) { EstateObject newEstate = new EstateObject(); newEstate.dealType = dealTypeComboBox.Text; newEstate.locality = localityComboBox.Text; newEstate.address = addressTextBox.Text; newEstate.area = areaTextBox.Text; newEstate.roomNumber = roomNumberComboBox.Text; newEstate.floor = floorTextBox.Text; newEstate.maxFloor = maxFloorTextBox.Text; newEstate.material = materialTextBox.Text; newEstate.price = priceTextBox.Text; newEstate.description = descriptionRichTextBox.Text; SQLitekurs.SQLite db = new SQLitekurs.SQLite(); db.AddEstate(newEstate); Close(); }
/// <summary> /// Method for adding user's estate object in database. /// </summary> /// <param name="newEstate">Exemplar of EstateObject entity</param> public void AddEstate(EstateObject newEstate) { Connect(@"C:\BD\RealtorEstateAgancy.sqlite"); connection.Open(); command = new SQLiteCommand("insert into EstateObject(dealType, locality, address, area, roomNumber, floor, maxFloor, " + "material, price, description) values (" + "'" + newEstate.dealType + "', " + "'" + newEstate.locality + "', " + "'" + newEstate.address + "', " + "'" + newEstate.area + "', " + "'" + newEstate.roomNumber + "', " + "'" + newEstate.floor + "', " + "'" + newEstate.maxFloor + "', " + "'" + newEstate.material + "', " + "'" + newEstate.price + "', " + "'" + newEstate.description + "');", connection); command.ExecuteNonQuery(); connection.Close(); }
public async Task <ActionResult> AddEstateObject(EstateObjectViewModel model) { if (!ModelState.IsValid) { Agency db = new Agency(); RealtyType result = db.RealtyTypes.FirstOrDefault(f => f.Id == model.RealtyTypeId); model = _estateObjectService.Model(); model.RealtyTypeId = result.Id; model.RealtyType = result.Name; return(View(model)); } EstateObject eo = await _estateObjectService.EstateObject(model); eo.StatusId = 1; await _estateObjectService.AddEstateObject(eo); return(RedirectToAction("Index")); }
public async Task <ActionResult> UpdateEstateObject(EstateObjectViewModel model) { if (ModelState.IsValid) { EstateObject eo = await _estateObjectService.EstateObject(model); await _estateObjectService.UpdateEstateObject(eo); return(RedirectToAction("Index")); } else { Agency db = new Agency(); EstateObject eo = await db.EstateObjects.FirstOrDefaultAsync(f => f.Id == model.Id); model = await _estateObjectService.Model(eo); return(View(model)); } }
public List <EstateObject> GetListEstate() { Connect(@"C:\BD\RealtorEstateAgancy.sqlite"); connection.Open(); command = new SQLiteCommand(connection); command.CommandText = @"SELECT id, dealType, locality, address, area, roomNumber, floor, maxFloor, material, price, description FROM EstateObject;"; SQLiteDataReader allDataReader = command.ExecuteReader(); DataTable allData = new DataTable(); allData.Load(allDataReader); allDataReader.Close(); connection.Close(); List <EstateObject> lstObj = new List <EstateObject>(); for (int i = 0; i < allData.Rows.Count; i++) { EstateObject tempEstObj = new EstateObject(); try { tempEstObj.id = Convert.ToInt32(allData.Rows[i].ItemArray[0]); tempEstObj.dealType = Convert.ToString(allData.Rows[i].ItemArray[1]); tempEstObj.locality = Convert.ToString(allData.Rows[i].ItemArray[2]); tempEstObj.address = Convert.ToString(allData.Rows[i].ItemArray[3]); tempEstObj.area = Convert.ToString(allData.Rows[i].ItemArray[4]); tempEstObj.roomNumber = Convert.ToString(allData.Rows[i].ItemArray[5]); tempEstObj.floor = Convert.ToString(allData.Rows[i].ItemArray[6]); tempEstObj.maxFloor = Convert.ToString(allData.Rows[i].ItemArray[7]); tempEstObj.material = Convert.ToString(allData.Rows[i].ItemArray[8]); tempEstObj.price = Convert.ToString(allData.Rows[i].ItemArray[9]); tempEstObj.description = Convert.ToString(allData.Rows[i].ItemArray[10]); } catch { } lstObj.Add(tempEstObj); } return(lstObj); }
public ActionResult DeleteObject(int id) { int?personid = HttpContext.Session.GetInt32("PersonID"); if (personid == null) { return(new UnauthorizedResult()); } else { EstateObject obj = new EstateObject(); if (DbClient.ObjectCache.TryGet(id, out obj)) { if (obj.SellerID != personid) { return(new UnauthorizedResult()); } ViewData["objectid"] = id; return(View("DeleteObject")); } return(new NotFoundResult()); } }
public ActionResult Post_Stage2() { if (HttpContext.Session.GetInt32("PersonID") == null) { return(new UnauthorizedResult()); } else { ViewData["LoggedIn"] = true; } EstateObject h; string variant = Request.Form["variant"]; switch (variant) { case "h": h = new House { PostDate = DateTime.UtcNow, LocationID = int.Parse(Request.Form["location"]), Variant = (byte)'h', StreetName = Request.Form["streetname"], HouseNumber = Request.Form["housenumber"], Description = Request.Form["description"], SellerID = (int)HttpContext.Session.GetInt32("PersonID"), Price = int.Parse(Request.Form["price"]), HomeArea = float.Parse(Request.Form["homearea"]), LandArea = float.Parse(Request.Form["landarea"]), FloorCount = short.Parse(Request.Form["floorcount"]), RoomCount = short.Parse(Request.Form["roomcount"]), State = byte.Parse(Request.Form["state"]), isVisible = true, isOpen = true }; break; case "f": h = new Flat { PostDate = DateTime.UtcNow, LocationID = int.Parse(Request.Form["location"]), Variant = (byte)'h', StreetName = Request.Form["streetname"], HouseNumber = Request.Form["housenumber"], FlatNumber = short.Parse(Request.Form["flatnumber"]), Description = Request.Form["description"], SellerID = (int)HttpContext.Session.GetInt32("PersonID"), Price = int.Parse(Request.Form["price"]), HomeArea = float.Parse(Request.Form["homearea"]), Floor = short.Parse(Request.Form["floor"]), RoomCount = short.Parse(Request.Form["roomcount"]), State = byte.Parse(Request.Form["state"]), isVisible = true, isOpen = true }; break; case "l": h = new Landplot { PostDate = DateTime.UtcNow, LocationID = int.Parse(Request.Form["location"]), Variant = (byte)'h', StreetName = Request.Form["streetname"], HouseNumber = Request.Form["housenumber"], Description = Request.Form["description"], SellerID = (int)HttpContext.Session.GetInt32("PersonID"), Price = int.Parse(Request.Form["price"]), LandArea = float.Parse(Request.Form["landarea"]), State = byte.Parse(Request.Form["state"]), isVisible = true, isOpen = true }; break; default: h = new EstateObject { PostDate = DateTime.UtcNow, LocationID = int.Parse(Request.Form["location"]), Variant = (byte)'h', StreetName = Request.Form["streetname"], HouseNumber = Request.Form["housenumber"], Description = Request.Form["description"], SellerID = (int)HttpContext.Session.GetInt32("PersonID"), Price = int.Parse(Request.Form["price"]), State = byte.Parse(Request.Form["state"]), isVisible = true, isOpen = true }; break; } string t = Request.Form["tags"]; h.Tags = t.Split(' '); var v = h.Validate; if (!v.isValid && v.FieldName != "PhotoUrls") // wheelchair { ViewData["ErrorMessage"] = v.Message; return(View("PostHouse", h)); } else { h.PhotoUrls = new List <string>(); var photos = Request.Form.Files.ToList(); if (photos.Count < 1) { ViewData["ErrorMessage"] = "There were no photos."; if (variant == "h") { return(View("PostHouse")); } else if (variant == "f") { return(View("PostFlat")); } else if (variant == "l") { return(View("PostLandplot")); } else { return(View("PostObject")); } } for (int i = 0; i < photos.Count & i < 10; i++) { if (photos[i].Length < (2 * 1024 * 1024)) { string ext = photos[i].ContentType.Split('/')[1]; string filename = $"{h.PostDate.ToBinary():X}_{i}.{ext}"; Console.WriteLine("File name: " + filename); h.PhotoUrls.Add(filename); using (FileStream s = new FileStream($"wwwroot/img/{filename}", FileMode.OpenOrCreate)) { photos[i].CopyTo(s); } } } try { DbClient.PutEstateObject(h); } catch (ReferentialException ee) { ViewData["ErrorMessage"] = ee.ReadableMessage; ViewData["location"] = Request.Form["location"]; ViewData["variant"] = "h"; if (variant == "h") { return(View("PostHouse")); } else if (variant == "f") { return(View("PostFlat")); } else if (variant == "l") { return(View("PostLandplot")); } else { return(View("PostObject")); } } } return(View("ViewObject", h)); }
public ActionResult CreateImage(EstateObject eo) { return(View()); }