public bool AddDriveCustomer([FromBody] DriveR k) { string ss = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Users.xml"); string ss1 = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Drives.xml"); List <Customer> users = xml.ReadUsers(ss); List <Drive> drives = xml.ReadDrives(ss1); User c = new Customer(); Drive drive = new Drive(); foreach (Customer u in users) { if (u.UserName == k.korisnicko) { c = u; Address a = new Address(k.Street); Location l = new Location(k.XCoord, k.YCoord, a); drive.Customer = (Customer)c; drive.Arrival = l; if (k.tipAuta != "") { drive.CarType = (Enums.CarType) int.Parse(k.tipAuta); } drive.Amount = 0; drive.Comment = new Comment(); drive.DataAndTime = String.Format("{0:F}", DateTime.Now); drive.Destination = new Location(); drive.Dispatcher = new Dispatcher(); drive.Driver = new Driver(); drive.Status = Enums.DriveStatus.Created_Waiting; } } drives.Add(drive); xml.WriteDrives(drives, ss1); return(true); }
public List <string> AddDriveDispatcher([FromBody] DriveR k) { ClosestDistance closest = new ClosestDistance(); string ss = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Users.xml"); string ss1 = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Drives.xml"); string adm = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Admins.xml"); string drv = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Drivers.xml"); List <Dispatcher> users = xml.ReadDispatcher(adm); List <Drive> drives = xml.ReadDrives(ss1); List <Driver> drivers = xml.ReadDrivers(drv); User c = new Dispatcher(); Drive drive = new Drive(); List <Tuple <Point, string> > proslediListu = new List <Tuple <Point, string> >(); foreach (Driver d in drivers) { if (!d.Blocked && !d.Zauzet && (d.Car.CarType == (Enums.CarType) int.Parse(k.tipAuta))) { Point poi = new Point(); poi.X = Double.Parse(d.Location.X); poi.Y = Double.Parse(d.Location.Y); proslediListu.Add(new Tuple <Point, string>(poi, d.UserName)); } } List <string> najblizi = new List <string>(); if (!proslediListu.Any()) { foreach (Dispatcher u in users) { if (u.UserName == k.korisnicko) { c = u; Address a = new Address(k.Street); Location l = new Location(k.XCoord, k.YCoord, a); drive.Customer = new Customer(); drive.Arrival = l; if (k.tipAuta != "") { drive.CarType = (Enums.CarType) int.Parse(k.tipAuta); } drive.Amount = 0; drive.Comment = new Comment(); drive.DataAndTime = String.Format("{0:F}", DateTime.Now); drive.Destination = new Location(); drive.Dispatcher = (Dispatcher)c; drive.Driver = new Driver(); drive.Status = Enums.DriveStatus.Created_Waiting; break; } } drives.Add(drive); xml.WriteDrives(drives, ss1); } else { Point ip = new Point(); ip.X = Double.Parse(k.XCoord); ip.Y = Double.Parse(k.YCoord); najblizi = closest.OrderByDistance(proslediListu, ip); } return(najblizi); }