private void PlaceCarsToPumps(PetrolStation petrolStation, List <Car> carList) { var carsInTheQueue = carList.Where(a => a.IsInTheQueue).ToList(); for (int i = 0; i < carsInTheQueue.Count; i++) { var oneCar = carsInTheQueue[i]; if (oneCar == null) { return; } var fuelPump = petrolStation.GetFuelPumpAvailableForPetrolRequired(oneCar.RequiredFuel); if (fuelPump != null) { oneCar.IsInTheQueue = false; fuelPump.ServingOneCar = oneCar; } else { break; } } }
public async Task <IHttpActionResult> PutPetrolStation(int id, PetrolStation petrolStation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != petrolStation.ID) { return(BadRequest()); } db.Entry(petrolStation).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PetrolStationExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult DeleteConfirmed(int id) { PetrolStation petrolStation = db.PetrolStations.Find(id); db.PetrolStations.Remove(petrolStation); db.SaveChanges(); return(RedirectToAction("Index")); }
public IHttpActionResult PostPetrolStation(string ImeNaBenzinska, string RabotnoVreme, string Dolzhina, string GeografskaShirochina, string TipoviGorivo, string Ocena) { PetrolStation petrolStation = new PetrolStation(ImeNaBenzinska, TipoviGorivo, RabotnoVreme, Double.Parse(GeografskaShirochina), Double.Parse(Dolzhina), float.Parse(Ocena)); db.PetrolStations.Add(petrolStation); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = petrolStation.PetrolStationId }, petrolStation)); }
public ActionResult Edit(PetrolStation petrolstation) { if (ModelState.IsValid) { db.Entry(petrolstation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(petrolstation)); }
// // GET: /PetrolStation/Delete/5 public ActionResult Delete(int id = 0) { PetrolStation petrolstation = db.PetrolStations.Find(id); if (petrolstation == null) { return(HttpNotFound()); } return(View(petrolstation)); }
public JsonResult PostRating(int Ocena, int PetrolStationId) { PetrolStation station = db.PetrolStations.FirstOrDefault(m => m.PetrolStationId == PetrolStationId); station.Ocena = Ocena; db.Entry(station).State = EntityState.Modified; db.SaveChanges(); return(Json("You rated this " + Ocena.ToString() + " star(s)")); }
public ActionResult Edit([Bind(Include = "PetrolStationId,ImeNaBenzinska,RabotnoVreme,Oddalecenost,Ocena")] PetrolStation petrolStation) { if (ModelState.IsValid) { db.Entry(petrolStation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(petrolStation)); }
public ActionResult Edit([Bind(Include = "ID,Name,Location,Petrol,Diesel")] PetrolStation petrolStation) { if (ModelState.IsValid) { db.Entry(petrolStation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(petrolStation)); }
public async Task <IHttpActionResult> GetPetrolStation(int id) { PetrolStation petrolStation = await db.PetrolStations.FindAsync(id); if (petrolStation == null) { return(NotFound()); } return(Ok(petrolStation)); }
public ActionResult Create([Bind(Include = "ID,Name,Location,Petrol,Diesel")] PetrolStation petrolStation) { if (ModelState.IsValid) { db.PetrolStations.Add(petrolStation); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(petrolStation)); }
public ActionResult Create([Bind(Include = "PetrolStationId,ImeNaBenzinska,RabotnoVreme,Oddalecenost,Ocena")] PetrolStation petrolStation) { if (ModelState.IsValid) { db.PetrolStations.Add(petrolStation); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(petrolStation)); }
public ActionResult Create(PetrolStation petrolstation) { if (ModelState.IsValid) { db.PetrolStations.Add(petrolstation); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(petrolstation)); }
public async Task <IHttpActionResult> PostPetrolStation(PetrolStation petrolStation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.PetrolStations.Add(petrolStation); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = petrolStation.ID }, petrolStation)); }
public ActionResult PetrolStationAdd(int companyId) { var modal = new PetrolStation { PetrolMarkets = false, PetrolTire = false, PetrolWashing = false, CompanyId = Convert.ToInt32(HttpContext.Session.GetString("UserId")) }; PetrolStationService.Add(modal); return(View("PetrolStationOparation", modal)); }
// GET: PetrolStations/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PetrolStation petrolStation = db.PetrolStations.Find(id); if (petrolStation == null) { return(HttpNotFound()); } return(View(petrolStation)); }
public async Task <IHttpActionResult> DeletePetrolStation(int id) { PetrolStation petrolStation = await db.PetrolStations.FindAsync(id); if (petrolStation == null) { return(NotFound()); } db.PetrolStations.Remove(petrolStation); await db.SaveChangesAsync(); return(Ok(petrolStation)); }
private bool PetrolStationCanFuelNextCarInTheQueue(PetrolStation petrolStation, List <Car> carList) { var carQueue = carList.Where(a => a.IsInTheQueue).ToList(); if (carQueue.Count == 0) { return(true); } var oneCar = carList.FirstOrDefault(a => a.IsInTheQueue); var canFuelAllCarsWaiting = petrolStation.MaxPumpCapacity() >= oneCar.RequiredFuel; return(canFuelAllCarsWaiting); }
/// <summary> /// Permite realizar la geocodificacion es decir, que permite pasar la dirección de un lugar a codigo. /// </summary> /// <param name="nameDepartament"></param> nombre del departamento donde se encuentra la estación de gasolina. /// <param name="municipality"></param> nombre del municipio donde se encuentra la estación de gasolina. /// <param name="aux"></param> private void Geocoding(string nameDepartament, string municipality, PetrolStation aux, GMarkerGoogleType type) { //geocodificación GeoCoderStatusCode statusCode; var pointLatng = OpenCycleMapProvider.Instance.GetPoint(nameDepartament + " " + municipality, out statusCode); var lat = pointLatng?.Lat.ToString(); var lng = pointLatng?.Lng.ToString(); if (lat != null && lng != null) { AddMarker(new PointLatLng(Double.Parse(lat), Double.Parse(lng)), type, aux); } }
public IHttpActionResult GetPetrolStation(int PetrolStationId) { //Го наоѓа објектот со специфицираното Id PetrolStation petrolStation = db.PetrolStations.Find(PetrolStationId); //Проверува дали таков објект постои во базата на податоци, со тоа што проверува дали вратениот објект е null if (petrolStation == null) { //If the specified petrol station is not present in the database, then it returns NotFound object //Доколку не постои таков објект враќа NotFound објект return(NotFound()); } //Доколку постои таков објект, врати го него return(Ok(petrolStation)); }
public IHttpActionResult DeletePetrolStation(int PetrolStationId) { //Го бара објектот со даденото Id во базата на податоци PetrolStation petrolStation = db.PetrolStations.Find(PetrolStationId); if (petrolStation == null) { return(NotFound()); } db.PetrolStations.Remove(petrolStation); db.SaveChanges(); return(Ok(petrolStation)); }
private PetrolStation CreatePetrolStation(int x, int y, int z) { var petrolStation = new PetrolStation(new FuelPump[] { new FuelPump { Capacity = x }, new FuelPump { Capacity = y }, new FuelPump { Capacity = z }, }); return(petrolStation); }
public IHttpActionResult PutPetrolStation(int PetrolStationId, string ImeNaBenzinska, string RabotnoVreme, string Dolzhina, string GeografskaShirochina, string TipoviGorivo, string Ocena) { //Проверува дали моделот е валиден if (!ModelState.IsValid) { //Враќа BadRequest доколку моделот не е валиден return(BadRequest(ModelState)); } //Find the petrol station with specified id or find default //Најди го објектот од тип PetrolStation во базата на бодатоци со дадено Id PetrolStation petrolStation = db.PetrolStations.FirstOrDefault(petrol => petrol.PetrolStationId == PetrolStationId); //Ажурирај ги податоците petrolStation.ImeNaBenzinska = ImeNaBenzinska; petrolStation.RabotnoVreme = RabotnoVreme; petrolStation.Dolzhina = Double.Parse(Dolzhina); petrolStation.GeografskaShirochina = Double.Parse(GeografskaShirochina); petrolStation.TipoviGorivo = TipoviGorivo; if (Ocena.Contains("Not Rated")) { petrolStation.Ocena = 0; } else { petrolStation.Ocena = float.Parse(Ocena); } db.Entry(petrolStation).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PetrolStationExists(PetrolStationId)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// Методот <c>CalculateEuqlide</c> /// ми го пресметува евклидовото растојание од бензинска A до /// бензинска Б /// </summary> /// <param name="model">Влезен аргумент од типот <c>DistanceCalculator</c></param> /// <returns> /// Враќа double вредност што ни претставува евклидово растојание /// </returns> private double CalculateEuqlide(DistanceCalculator model) { //Ги зема објектите од тип PetrolStation од базата на податоци со дадено Id PetrolStation from = db.PetrolStations.FirstOrDefault(m => m.PetrolStationId == model.FromId); PetrolStation to = db.PetrolStations.FirstOrDefault(m => m.PetrolStationId == model.ToId); //Во продолжение следува алгоритам за пресметување на евклидово растојание double latDistance = Math.Abs(from.Dolzhina - to.Dolzhina); double lngDistance = Math.Abs(from.Dolzhina - to.Dolzhina); double a = Math.Sin(latDistance / 2) * Math.Sin(latDistance / 2) + Math.Cos(from.GeografskaShirochina) * Math.Cos(to.GeografskaShirochina) * Math.Sin(lngDistance / 2) * Math.Sin(lngDistance / 2); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); return(Math.Round(6371 * c)); }
public JsonResult GetTypesOfOils(int PetrolStationId) { PetrolStation station = db.PetrolStations.FirstOrDefault(m => m.PetrolStationId == PetrolStationId); List <String> types_oils = GetFuels(station); if (types_oils.Count == 0 || types_oils.Contains("Непознато")) { return(Json("Непознато")); } String finalString = ""; foreach (String s in types_oils) { finalString += s + ", "; } return(Json(finalString.Substring(0, finalString.Length - 2))); }
/// <summary> /// Методот <c>GetFuels</c> /// ги наоѓа сите типови на гориво /// за дадената бензинска станица /// </summary> /// <param name="petrolStation">Објект од типот PetrolStation за којшто бараме типови на гориво</param> /// <returns> /// Враќа листа со имиња од сите типови на гориво коишто се присутни во дадената бензинска станица /// </returns> public List <String> GetFuels(PetrolStation petrolStation) { List <String> fuelList = new List <string>(); List <int> getAllFuelsWithStationId = db.PetrolStationFuels.Where(r => r.PetrolStation_PetrolStationId == petrolStation.PetrolStationId). Select(r => r.Fuel_FuelId).ToList(); if (getAllFuelsWithStationId != null) { foreach (int id in getAllFuelsWithStationId) { fuelList.Add(db.Fuels.FirstOrDefault(r => r.FuelId == id).Name); } } else { fuelList.Add("Непознато"); } return(fuelList); }
public ActionResult AddPrice(AddPetrolPriceCommand petrolPrice) { if (ModelState.IsValid) { PetrolStation petrolstation = db.PetrolStations.Find(petrolPrice.PetrolStationId); if (petrolstation == null) { return(HttpNotFound()); } else { var price = new PetrolPrice(); petrolPrice.TransferTo(price); price.StartTime = DateTime.Now; petrolstation.Prices.Add(price); db.SaveChanges(); return(RedirectToAction("Details", new { id = petrolPrice.PetrolStationId })); } } return(View(petrolPrice)); }
private void ViewCalculateButtonClicked(object sender, EventArgs e) { PetrolStation petrol = new PetrolStation { Gasoline = _view.GasolineText, Price = _view.PriceText, ByGallon = _view.ByGallonText, ByCash = _view.ByCashText, ResultPrice = _view.ResultPrice, }; _db.PetrolStations.Add(petrol); _db.SaveChanges(); var list = _db.PetrolStations.ToList(); _view.PetrolStations = list; }
private void AddMarker(PointLatLng pointToAdd, GMarkerGoogleType gMarkerGoogleType, PetrolStation aux) { var markerOverlay = new GMapOverlay("markers"); var marker = new GMarkerGoogle(pointToAdd, gMarkerGoogleType); markerOverlay.Markers.Add(marker); marker.ToolTipMode = MarkerTooltipMode.OnMouseOver; marker.ToolTipText = String.Format("Mes: " + aux.Month + "\n" + "Departament: " + aux.NameDepartment + "\n" + "Municipio: " + aux.NameMunicipality + "\n" + "Nombre comercial: " + aux.TradeName + "\n" + "Bandera: " + aux.Flag + "\n" + "Direccion: " + aux.Addres + "\n" + "Producto: " + aux.TypeProduct + "\n" + "Precio: " + aux.Price); gMapC.Overlays.Add(markerOverlay); }
private void insertToDatabase() { using (StreamReader file = new StreamReader("~/Petrol_Stations Dataset/petrol_stations.csv")) { int counter = 0; string ln; db.Fuels.Add(new Fuel("Diesel")); db.Fuels.Add(new Fuel("Biodiesel")); db.Fuels.Add(new Fuel("Octane 95")); db.Fuels.Add(new Fuel("Octane 98")); db.Fuels.Add(new Fuel("Octane 100")); db.Fuels.Add(new Fuel("LPG")); db.SaveChanges(); while ((ln = file.ReadLine()) != null) { bool diesel = false, biodiesel = false, octane_95 = false, octane_98 = false , octane_100 = false, lpg = false; string[] splitted = ln.Split(','); string name = splitted[2]; List <Fuel> vidoviGorivo = new List <Fuel>(); if (splitted[5].Equals("yes")) { vidoviGorivo.Add(db.Fuels.FirstOrDefault(m => m.FuelId == 1)); diesel = true; } if (splitted[6].Equals("yes")) { vidoviGorivo.Add(db.Fuels.FirstOrDefault(m => m.FuelId == 2)); biodiesel = true; } if (splitted[7].Equals("yes")) { vidoviGorivo.Add(db.Fuels.FirstOrDefault(m => m.FuelId == 3)); octane_95 = true; } if (splitted[8].Equals("yes")) { vidoviGorivo.Add(db.Fuels.FirstOrDefault(m => m.FuelId == 4)); octane_98 = true; } if (splitted[9].Equals("yes")) { vidoviGorivo.Add(db.Fuels.FirstOrDefault(m => m.FuelId == 5)); octane_100 = true; } if (splitted[10].Equals("yes")) { vidoviGorivo.Add(db.Fuels.FirstOrDefault(m => m.FuelId == 6)); lpg = true; } string vreme = splitted[4]; float ocena = 0; double shirina = double.Parse(splitted[0]); double dolzhina = double.Parse(splitted[1]); PetrolStation toAdd = new PetrolStation(name, vidoviGorivo, vreme, shirina, dolzhina, ocena); // Fuel f = db.Fuels[0]; db.PetrolStations.Add(toAdd); if (diesel) { db.Fuels.FirstOrDefault(m => m.FuelId == 1).Petrols.Add(toAdd); } if (biodiesel) { db.Fuels.FirstOrDefault(m => m.FuelId == 2).Petrols.Add(toAdd); } if (octane_95) { db.Fuels.FirstOrDefault(m => m.FuelId == 3).Petrols.Add(toAdd); } if (octane_98) { db.Fuels.FirstOrDefault(m => m.FuelId == 4).Petrols.Add(toAdd); } if (octane_100) { db.Fuels.FirstOrDefault(m => m.FuelId == 5).Petrols.Add(toAdd); } if (lpg) { db.Fuels.FirstOrDefault(m => m.FuelId == 6).Petrols.Add(toAdd); } Console.WriteLine(ln); counter++; } } db.SaveChanges(); }