private async Task <Response> UpdateGasStationAsync(GasStation gasStation, GasStationDto dto) { var response = Response.Create(); var newAddressResponse = Address.Create(dto.Address.Cep, dto.Address.StreetAddress, dto.Address.City, dto.Address.UF, dto.Address.Complement); if (newAddressResponse.HasError) { return(response.WithMessages(newAddressResponse.Messages)); } if (!newAddressResponse.Equals(gasStation.Address)) { var updateAddresResponse = await UpdateAddressAsync(newAddressResponse); if (updateAddresResponse.HasError) { return(updateAddresResponse); } } var updateGasStationResponse = gasStation.Update(dto, newAddressResponse); if (updateGasStationResponse.HasError) { return(updateGasStationResponse); } if (!(await GasStationRepository.UpdadeAsync(gasStation)).IsAcknowledged) { return(response.WithCriticalError($"Failed to save gas station {gasStation.ExternalId}")); } return(response); }
public static void Create(GasStation _model) { _model.GasStationId = CurrentGasStations.Item1.Count > 0 ? CurrentGasStations.Item1.LastOrDefault().GasStationId + 1 : 1; CurrentGasStations.Item1.Add(_model); CurrentGasStations.Item2.Add(API.shared.createTextLabel("Stok: " + _model.GasInStock + "/" + _model.MaxGasInStock + "((/benzin))", _model.Position, 15, 1, true, _model.Dimension)); SaveChanges(); }
/// <summary> /// Konstruktor /// </summary> public AdminArea() { InitializeComponent(); List <IAdminMessage> messages = new List <IAdminMessage>(); foreach (Tank tank in GasStation.GetInstance().TankList) { //Schaut ob genügend Treibstoff im Tank ist if (!TankService.HasEnoughInTank(tank)) { IAdminMessage message = new AdminMessage(); message.Status = MessageStatus.Warning; message.Description = "Das Tank minimum wurde im Tank " + tank.Name + " erreicht"; messages.Add(message); } //Vergleicht mit dem letzten Jahr und schaut ob genügend Treibstoff im Tank ist if (TankService.AdjustTankMinimum(tank)) { IAdminMessage message = new AdminMessage(); message.Status = MessageStatus.Warning; message.Description = "Letztes Jahr wurde im Tank: " + tank.Name + " der Treibstoff sehr knapp"; messages.Add(message); } } messageList.ItemsSource = messages; }
public IActionResult UpdateGasStation(int id, [FromBody] UpdateGasStationViewModel viewModel) { GasStation _gasStation = _gasStationService.Get(id); if (_gasStation is null) { return(NotFound()); } if (ModelState.IsValid) { // Atualizar _gasStation.Name = viewModel.Name; _gasStation.CEP = viewModel.CEP; _gasStation.Street = viewModel.Street; _gasStation.Number = viewModel.Number; _gasStation.Neighborhood = viewModel.Neighborhood; _gasStation.City = viewModel.City; _gasStation.UF = viewModel.UF; return(Ok(_gasStationService.Update(_gasStation))); } else { return(BadRequest()); } }
public async Task <Response> CreateAsync(GasStationDto dto) { var response = Response.Create(); var addressResponse = await CreateAddressAsync(dto); if (addressResponse.HasError) { return(response.WithMessages(addressResponse.Messages)); } var gasStationResponse = GasStation.Create(dto, addressResponse); if (gasStationResponse.HasError) { return(response.WithMessages(gasStationResponse.Messages)); } var addGasStationResponse = await GasStationRepository.AddAsync(gasStationResponse); if (addGasStationResponse.HasError) { return(response.WithMessages(addGasStationResponse.Messages)); } return(response); }
public ActionResult Create([Bind(Include = "Id,GasStationName,Description,Latitude,Longitude,Email,Address,FK_Category,Phone,Image,FK_AreaId,Website")] GasStation gasStation, HttpPostedFileBase img) { if (ModelState.IsValid) { string file_name = ""; if (img != null && img.ContentLength > 0) { try { file_name = Guid.NewGuid() + Path.GetFileName(img.FileName); string path = Path.Combine(Server.MapPath("~/images"), file_name); img.SaveAs(path); } catch (Exception ex) { ViewBag.Message = "ERROR:" + ex.Message.ToString(); } } gasStation.Image = file_name; db.GasStations.Add(gasStation); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.FK_AreaId = new SelectList(db.Areas, "Id", "AreaName", gasStation.FK_AreaId); ViewBag.FK_Category = new SelectList(db.Categories, "Id", "CategoryName", gasStation.FK_Category); return(View(gasStation)); }
public List <GasStation> GetGasStations() { if (_connection.State != ConnectionState.Open) { _connection.Open(); } var stations = new List <GasStation>(); var command = new MySqlCommand("SELECT * FROM `gas_stations`;", _connection); using (var reader = command.ExecuteReader()) { if (!reader.HasRows) { return(stations); } while (reader.Read()) { var gasStation = new GasStation { ID = reader.GetInt32("ID"), Location = JsonConvert.DeserializeObject <Vector3>(reader.GetString("Location")), ProviderLocations = JsonConvert .DeserializeObject <Vector3[]>(reader.GetString("ProviderLocations")).ToList() }; stations.Add(gasStation); } } return(stations); }
private async Task <IReadOnlyCollection <SubmitPriceModel> > GetPrices(GasStation gasStation) { var store = await SendRequest <AuchanStoreResponse>(AuchanStoresUrl + gasStation.WebsiteAddress); return(store?.gasstation?.state == true?store.gasstation.gas_types?.Select(x => ToPriceSubmission(gasStation.Id, x)) .Where(x => x.FuelType != FuelType.None).ToArray() ?? Array.Empty <SubmitPriceModel>() : Array.Empty <SubmitPriceModel>()); }
public async Task <IActionResult> CreateGasStation(GasStation gs) { var request = new CreateGasStationRequest() { CNPJ = gs.CNPJ, Name = gs.Name, CEP = gs.CEP, City = gs.City, Neighborhood = gs.Neighborhood, Number = gs.Number, Street = gs.Street, UF = gs.UF }; var success = await _movtechAPIService.CreateGasStation(request); var viewModel = new RefuelIndexViewModel() { Postos = await GetPostos() }; ViewBag.PostoCriado = "true"; return(View("Index", viewModel)); }
public static void Main(string[] args) { Car myCar = new Car("Zastava", "101", "Bela", 45, true); Car myCar2 = new Car("Ficho", "500", "Siva", 75, true); Console.WriteLine(Car.GetCarStats(myCar)); myCar.StartCar(); myCar.StartLights(); myCar.Drive("Sofija"); GasStation.Refill(myCar); myCar.Drive("Sofija"); GasStation.PumpUpTires(myCar); Console.WriteLine("-----------------------------------------------------------"); Console.WriteLine(Car.GetCarStats(myCar2)); myCar2.StartCar(); myCar2.StartLights(); myCar2.Drive("Sofija"); GasStation.Refill(myCar2); GasStation.PumpUpTires(myCar2); Console.ReadLine(); }
public IActionResult CreateGasStation([FromBody] CreateGasStationViewModel viewModel) { try { if (ModelState.IsValid) { GasStation _gasStation = new GasStation() { CNPJ = viewModel.CNPJ, Name = viewModel.Name, CEP = viewModel.CEP, Street = viewModel.Street, Number = viewModel.Number, Neighborhood = viewModel.Neighborhood, City = viewModel.City, UF = viewModel.UF }; return(Created("", _gasStationService.Insert(_gasStation))); } else { return(BadRequest()); } } catch (Exception ex) { return(BadRequest(ex.InnerException)); } }
public void PatchGasStation(int id, GasStation gasStation) { var gasStationGet = _context.GasStations.FirstOrDefault(a => a.Id == id); if (gasStation.Latitude != null) { gasStationGet.Latitude = gasStation.Latitude; } if (gasStation.Longtitude != null) { gasStationGet.Longtitude = gasStation.Longtitude; } if (gasStation.Name != null) { gasStationGet.Name = gasStation.Name; } if (gasStation.City != null) { gasStationGet.City = gasStation.City; } if (gasStation.Address != null) { gasStationGet.Address = gasStation.Address; } _context.SaveChanges(); }
public async Task UpdateGasStations() { var gasStations = await gasStationsFetcher.GetAuchanGasStations(); var gasStationsQueryValues = string.Join(",", gasStations.Select((x, n) => $"({n}, '{x.Name}')")); var franchiseId = franchiseCollection.Auchan; var missingGasStations = await dbContext.Database.GetDbConnection().QueryAsync <int>($@" SELECT n FROM (VALUES { gasStationsQueryValues }) as request (n, name) LEFT JOIN ""{ nameof(GasStation) }s"" stations ON stations.""{ nameof(GasStation.Name) }"" = request.name AND stations.""{ nameof(GasStation.FranchiseId) }"" = { franchiseId } WHERE stations.""{ nameof(GasStation.Id) }"" IS NULL"); foreach (var index in missingGasStations) { var missingGasStation = gasStations[index]; var gasStation = new GasStation( name: missingGasStation.Name, addressLine1: missingGasStation.AddressLine1, addressLine2: missingGasStation.AddressLine2, franchiseId: franchiseId, maintainedBySystem: true, websiteAddress: missingGasStation.WebsiteAddress); auditMetadataProvider.AddAuditMetadataToNewEntity(gasStation); dbContext.Add(gasStation); } await dbContext.SaveChangesAsync(); }
public static double GetFuelPrice(GasStation gasStation, FuelType fuelType) { double price = 0; switch (fuelType) { case FuelType.Petrol: price = gasStation.StationFuelPrices.Petrol; break; case FuelType.Diesel: price = gasStation.StationFuelPrices.Diesel; break; case FuelType.Gas: price = gasStation.StationFuelPrices.Gas; break; case FuelType.Electricity: price = gasStation.StationFuelPrices.Electricity; break; case FuelType.Kerosene: price = gasStation.StationFuelPrices.Kerosene; break; } return(price); }
public static void StopRefill(Client client) { if (!client.hasData("player")) { return; } Player player = client.getData("player"); API.shared.triggerClientEvent(client, "HideRefuelProgressbar"); API.shared.stopTimer((Timer)client.getData("refuelTimer")); OwnedVehicle ownedVehicle = client.getData("fuelcar"); GasStation gasStation = client.getData("gasStation"); FuelType fuelType = client.getData("fueltype"); int fuelStart = client.getData("fuelcarstart"); int fueled = ownedVehicle.Fuel - fuelStart; API.shared.sendNotificationToPlayer(client, "~b~Refuel Stopped~n~~w~You paid ~g~" + (fueled * GetFuelPrice(gasStation, fuelType)) + "$"); client.resetData("refuelTimer"); client.resetData("fuelStartPosition"); client.resetData("fuelcar"); client.resetData("fuelcarstart"); client.resetSyncedData("currentfuel"); UpdateGasStation(gasStation); client.resetData("gasStation"); client.resetData("fueltype"); CharacterService.CharacterService.UpdateCharacter(player.Character); }
public static void LoadAllGasStationsFromDB() { Dictionary <string, string> parameters = new Dictionary <string, string>(); DataTable result = DatabaseHandler.ExecutePreparedStatement("SELECT * FROM gasstations", parameters); if (result.Rows.Count != 0) { foreach (DataRow row in result.Rows) { GasStation gasStation = new GasStation { Id = (int)row["Id"], Position = new Vector3((float)row["PosX"], (float)row["PosY"], (float)row["PosZ"]), GasPumps = JsonConvert.DeserializeObject <List <Vector3> >((string)row["GasPumps"]), StationFuelPrices = JsonConvert.DeserializeObject <FuelPrices>((string)row["FuelPrices"]), Storage = JsonConvert.DeserializeObject <FuelStorage>((string)row["Storage"]), MoneyStorage = (double)row["MoneyStorage"] }; gasStation.MapMarker = API.shared.createBlip(gasStation.Position); gasStation.MapMarker.shortRange = true; gasStation.MapMarker.sprite = 361; gasStation.MapMarker.scale = 0.75f; GasStationList.Add(gasStation); BlipService.BlipService.BlipList.Add(gasStation.MapMarker); } API.shared.consoleOutput(LogCat.Info, result.Rows.Count + " Gas Stations Loaded.."); } else { API.shared.consoleOutput(LogCat.Info, "No Gas Stations Loaded.."); } }
public void CanInsertTanksAndGetTanksFromDatabase() { _builder.UseInMemoryDatabase("CanInsertTanksAndGetTanks"); using (var context = new AdministrationContext(_builder.Options)) { var guid = Guid.NewGuid(); var gasStation = new GasStation(guid); var tank = new Tank(); tank.GasStationId = guid; tank.Number = 1; tank.ProductId = 1; tank.Name = "Tank1"; tank.AddMeasurement(new Measurement(TankMeasurement.Gallons, 100, 100, 800)); gasStation.Tanks.Add(tank); context.GasStations.Add(gasStation); Assert.NotEqual(default(Guid), gasStation.Id); Assert.NotEqual(default(Guid), tank.GasStationId); Assert.Equal(EntityState.Added, context.Entry(tank).State); context.SaveChanges(); var tanks = context.Tanks.Where(t => t.GasStationId == gasStation.Id).ToList(); Assert.Single(tanks); } }
public void Start() { _GroceryStore = GameObject.Find("GroceryStore").GetComponent <GroceryStore>(); _Hospital = GameObject.Find("Hospital").GetComponent <Hospital>(); _Colany = GameObject.Find("Colany").GetComponent <Colany> (); _GasStation = GameObject.Find("GasStation").GetComponent <GasStation> (); _ZombiePopup = GameObject.Find("Popup Canvas").GetComponent <ZombiePopup> (); }
public ActionResult DeleteConfirmed(int id) { GasStation gasStation = db.GasStations.Find(id); db.GasStations.Remove(gasStation); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// Add new GasStation /// </summary> /// <param name="gasStation"></param> /// <returns></returns> public async Task <GasStation> AddGasStationAsync(GasStation gasStation) { await _context.AddAsync(gasStation); await _context.SaveChangesAsync(); return(gasStation); }
private static void addNewGasStation(LinkedList <GasStation> list) { GasStation station = new GasStation(); setStationName(station); setDistanceToGasStation(station); setFuelPrice(station); list.AddFirst(station); }
public void TestCanCompleteCircuit() { var r = GasStation.CanCompleteCircuit(new[] { 1, 2, 3, 4, 5 }, new[] { 3, 4, 5, 1, 2 }); Assert.AreEqual(r, 3); r = GasStation.CanCompleteCircuit(new[] { 2, 3, 4 }, new[] { 3, 4, 3 }); Assert.AreEqual(r, -1); }
public GasStationTests() { _gasStationName = "G1"; _address = "111"; _id = Guid.NewGuid(); _gasStation = new GasStation(_id); _gasStation.Name = _gasStationName; _gasStation.Address = _address; }
public static void SaveGasPumps(GasStation gasStation) { Dictionary <string, string> parameters = new Dictionary <string, string> { { "@Id", gasStation.Id.ToString() }, { "@GasPumps", JsonConvert.SerializeObject(gasStation.GasPumps) } }; DataTable result = DatabaseHandler.ExecutePreparedStatement("UPDATE gasstations SET GasPumps = @GasPumps WHERE Id = @Id LIMIT 1", parameters); }
public async Task <UpdateResult> DeleteAsync(GasStation gasStation) { var filter = Builders <GasStation> .Filter.Eq(_ => _.ExternalId, gasStation.ExternalId); var update = Builders <GasStation> .Update .CurrentDate(nameof(gasStation.DeletedAt)) .CurrentDate(nameof(gasStation.LastUpdate)); return(await Collection.UpdateOneAsync(filter, update)); }
/// <summary> /// Erhalte die anzahl Liter eines Tages /// </summary> /// <param name="date"></param> /// <param name="fuel"></param> /// <returns></returns> public static float GetSoldLiters(DateTime date, Fuel fuel) { float litercount = 0; foreach (Receipt receipt in GasStation.GetInstance().ReceiptList.Where(x => x.Date.Date == date.Date && x.RelatedFuel == fuel)) { litercount += receipt.RelatedLiter; } return(litercount); }
/// <summary> /// Erhalte die Einnahmen eines Jahres /// </summary> /// <param name="date"></param> /// <returns></returns> public static decimal GetYearEarning(DateTime date) { decimal earnings = 0; foreach (Receipt receipt in GasStation.GetInstance().ReceiptList.Where(x => x.Date.Year == date.Year)) { earnings += receipt.Sum; } return(earnings); }
/// <summary> /// Erhalte die Einnahmen einer Woche /// </summary> /// <param name="date"></param> /// <returns></returns> public static decimal GetWeekEarning(DateTime date) { decimal earnings = 0; foreach (Receipt receipt in GasStation.GetInstance().ReceiptList.Where(x => GetWeekBegin(x.Date) == GetWeekBegin(date))) { earnings += receipt.Sum; } return(earnings); }
public ActionResult Edit([Bind(Include = "Id,County,CountyID,Municipality,DepId,Dep,Address,Brand,Latitude,Longitude,Price,PriceUpdate,FuelType,Name,Phone")] GasStation gasStation) { if (ModelState.IsValid) { db.Entry(gasStation).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(gasStation)); }
public void PutGasStation(int id, GasStation gasStation) { var gasStationGet = _context.GasStations.FirstOrDefault(a => a.Id == id); gasStationGet.Latitude = gasStation.Latitude; gasStationGet.Longtitude = gasStation.Longtitude; gasStationGet.Name = gasStation.Name; gasStationGet.Address = gasStation.Address; gasStationGet.City = gasStation.City; _context.SaveChanges(); }