private async Task <StatusCodeResult> ValidateFuelSupply(FuelSupply fuelSupply) { Guid responsibleId = new Guid(fuelSupply.ResponsibleUserId.ToString()); Guid vehicleId = new Guid(fuelSupply.VehicleId.ToString()); bool existsError = false; if (!Enum.IsDefined(typeof(FuelType), fuelSupply.FuelType)) { ModelState.AddModelError("", "Este tipo de combustível não existe, para mais informação consute o suporte"); existsError = true; } if (!await _userRepository.UserExists(responsibleId)) { ModelState.AddModelError("", "O usuário informado não existe"); existsError = true; } if (!await _vehicleRepository.ExistsVehicle(vehicleId)) { ModelState.AddModelError("", "O veículo informado não existe"); existsError = true; } return(existsError ? StatusCode(404) : null); }
void Start() { rbody = GetComponent <Rigidbody> (); fuelSupply = FindObjectOfType <FuelSupply> (); FindObjectOfType <Statistics> ().AddMass(mass); FindObjectOfType <Statistics> ().AddPower(power); }
public double FuelUsage(Fleet fleet, Vector2D fromPosition, Vector2D toPosition, MainGame game) { //TODO(v0.8) make temporary stat for fleets var fleetSize = fleet.Ships.Sum(x => x.Design.UsesFuel ? this.DesignStats[x.Design].Size * x.Quantity : 0); var stellarises = game.States.Stellarises.OwnedBy[this.Player]; if (fleetSize <= 0) { return(0); } else if (fromPosition == toPosition) { return(fleetSize * game.Statics.ShipFormulas.FuelUsage.Evaluate(new Var("dist", 0).Get)); } else if (stellarises.Any()) { var seed = stellarises.First().Location.Star.Position; var intervals = new LinkedList <FuelSupply>(); intervals.AddLast(new FuelSupply(fromPosition, seed, fromPosition, toPosition)); intervals.AddLast(new FuelSupply(toPosition, seed, fromPosition, toPosition)); foreach (var center in stellarises.Skip(1).Select(x => x.Location.Star.Position)) { var node = intervals.First; while (node.Next != null) { var intersection = FuelSupply.Intersection(node.Value, node.Next.Value, center); node.Value = node.Value.Improve(center); if (intersection != null) { intervals.AddAfter(node, intersection); node = node.Next; } node = node.Next; } intervals.Last.Value = intervals.Last.Value.Improve(center); } var supplyDistance = intervals.Max(x => x.Distance); return(fleetSize * game.Statics.ShipFormulas.FuelUsage.Evaluate(new Var("dist", supplyDistance).Get)); } else { return(double.PositiveInfinity); } }
public async Task <IActionResult> CreateFuelSupply([FromBody] FuelSupply fuelSupply) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var statusCode = await ValidateFuelSupply(fuelSupply); if (!ModelState.IsValid) { return(StatusCode(statusCode.StatusCode, ModelState)); } if (!await _fuelSupplyRepository.CreateFuelSupply(fuelSupply)) { ModelState.AddModelError("", $"Ocorreu um erro ao salvar o abasteciemnto"); return(StatusCode(500, ModelState)); } var fuelSupplyDTO = _mapper.Map <FuelSupplyResponseDTO>(fuelSupply); return(CreatedAtRoute("GetFuelSupply", new { fuelSupplyId = fuelSupplyDTO.Id }, fuelSupplyDTO)); }
public async Task <bool> DeleteFuelSupply(FuelSupply fuelSupply) { _fuelSupplyContext.Remove(fuelSupply); return(await Save()); }
public async Task <bool> UpdateFuelSupply(FuelSupply fuelSupply) { _fuelSupplyContext.Update(fuelSupply); return(await Save()); }
public async Task <bool> CreateFuelSupply(FuelSupply fuelSupply) { _fuelSupplyContext.Add(fuelSupply); return(await Save()); }