private async Task SubstitutionTurvo(PartsCars newPart, Parts oldPart, int id) { if (oldPart == null) { var newTurbo = dbContext.Turbos.Add(new Turbo { CarId = id, Name = newPart.Name, Price = newPart.Price, Strength = newPart.Strength, Speed = newPart.Speed, }); await dbContext.SaveChangesAsync(); var car = GetCar(id).Result; car.TurboId = newTurbo.Entity.Id; } else { oldPart.Name = newPart.Name; oldPart.Price = newPart.Price; oldPart.Strength = newPart.Strength; oldPart.Speed = newPart.Speed; } await dbContext.SaveChangesAsync(); }
private void ReplacedOldPartWhithNew(PartsCars part, Cars car) { if (part.Type.ToString() == "Aerodynamics") { cars.GetNewAerodynamics(part, car); } else if (part.Type.ToString() == "Brakes") { cars.GetNewBrakes(part, car); } else if (part.Type.ToString() == "Engines") { cars.GetNewEngine(part, car); } else if (part.Type.ToString() == "GearBoxs") { cars.GetNewGearbox(part, car); } else if (part.Type.ToString() == "ModelsCars") { cars.GetNewModelsCar(part, car); } else if (part.Type.ToString() == "Mountings") { cars.GetNewMountings(part, car); } else if (part.Type.ToString() == "Turbo") { cars.GetNewTurbo(part, car); } }
private async Task Substitution(PartsCars newPart, Parts oldPart) { oldPart.Name = newPart.Name; oldPart.Price = newPart.Price; oldPart.Strength = newPart.Strength; oldPart.Speed = newPart.Speed; await dbContext.SaveChangesAsync(); }
public void CorrectReplacedOldPartWhithNew() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new ApplicationDbContext(options.Options); var market = new MarketServices(repository); var part = new PartsCars { Name = "Engen", Type = PartsCarsType.Engines, Speed = 100, Strength = 100, CarId = 1, Price = 100, IsDeleted = false, Id = 1, }; var car = new Cars { EngineId = 1, GearboxId = 1, TeamId = 2, AerodynamicsId = 1, BrakesId = 1, ModelCarId = 1, MountingId = 1, TurboId = null, Id = 1 }; //for Copy }
public void CorrectGetNewAerodynamics() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new ApplicationDbContext(options.Options); var cars = new CarServices(repository); var parts = new PartsCars { Id = 1, Name = "Aerodynamics", Price = 100, Speed = 40, Strength = 50, IsDeleted = false, }; var car = new Cars { EngineId = 1, GearboxId = 1, TeamId = 2, AerodynamicsId = 1, BrakesId = 1, ModelCarId = 1, MountingId = 1, TurboId = null, Id = 1, }; cars.GetNewAerodynamics(parts, car); var newCar = cars.GetCar(1); var resultSpeed = newCar.Aerodynamics.Speed; Assert.Equal(40, resultSpeed); }
public void GetNewTurbo(PartsCars part, Cars car) { var oldPart = GetTurboId(car.TurboId).Result; SubstitutionTurvo(part, oldPart, car.Id).GetAwaiter(); }
public void GetNewMountings(PartsCars part, Cars car) { var oldPart = GetMountings(car.MountingId); Substitution(part, oldPart).GetAwaiter(); }
public void GetNewModelsCar(PartsCars part, Cars car) { var oldPart = GetModelsCars(car.ModelCarId); Substitution(part, oldPart).GetAwaiter(); }
public void GetNewGearbox(PartsCars part, Cars car) { var oldPart = GetGearboxs(car.GearboxId); Substitution(part, oldPart).GetAwaiter(); }
public void GetNewEngine(PartsCars part, Cars car) { var oldPart = GetEngine(car.EngineId); Substitution(part, oldPart).GetAwaiter(); }
public void GetNewBrakes(PartsCars part, Cars car) { var oldPart = GetBrakes(car.BrakesId); Substitution(part, oldPart).GetAwaiter(); }
public void GetNewAerodynamics(PartsCars part, Cars car) { var oldPart = GetAerodynamics(car.AerodynamicsId).Result; Substitution(part, oldPart).GetAwaiter(); }