RealEstate1/RealEstate/Ad.cs
kuncsanadlajos a0a6b91945 8.
2024-04-18 13:13:25 +02:00

97 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace RealEstate
{
public class Ad
{
public int Area
{
get; set;
}
public Category Category
{
get; set;
}
public DateTime CreateAt
{
get; set;
}
public string Description
{
get; set;
}
public int Floors
{
get; set;
}
public bool FreeOfCharge
{
get; set;
}
public int Id
{
get; set;
}
public string ImageUrl
{
get; set;
}
public string LatLong
{
get; set;
}
public int Rooms
{
get; set;
}
public Seller Seller
{
get; set;
}
public static List<Ad> LoadFromCsv(string filename)
{
List<Ad> lista = new List<Ad>();
string[] sorok = File.ReadAllLines(filename);
for (int i = 1; i < sorok.Length; i++)
{
lista.Add(new Ad(sorok[i]));
}
return lista;
}
public Ad(string adatsor)
{
string[] t = adatsor.Split(';');
Id = int.Parse(t[0]);
Rooms = int.Parse(t[1]);
LatLong = t[2];
Floors = int.Parse(t[3]);
Area = int.Parse(t[4]);
Description = t[5];
FreeOfCharge = (t[6] == "1");
ImageUrl = t[7];
CreateAt = DateTime.Parse(t[8]);
Seller = new Seller(int.Parse(t[9]), t[10], t[11]);
Category = new Category(int.Parse(t[12]), t[13]);
}
//7. feladat
public double DistanceTo(double lat2, double long2)
{
double lat1 = double.Parse(LatLong.Split(',')[0].Replace('.',','));
double long1 = double.Parse(LatLong.Split(',')[1].Replace('.',','));
return Math.Sqrt(Math.Pow(lat1-lat2,2)+ Math.Pow(long1-long2,2));
}
}
}