/// <summary> /// Buys a part design. /// </summary> /// <param name="theTeam">The team which is buying.</param> /// <param name="theDesign">The design to buy.</param> public void BuyPartDesign(Team theTeam, PartDesign theDesign) { if (theTeam == null) { throw new ArgumentNullException("theTeam"); } if (theDesign == null) { throw new ArgumentNullException("theDesign"); } if (theDesign.BasedOn != null) { throw new InvalidOperationException("Part design is not a base design."); } var teamRepo = this.container.Resolve<ITeamRepository>(); var uow = this.container.Resolve<IUnitOfWork>(); PartDesign theNewDesign = new PartDesign() { BasedOn = theDesign, DevelopmentState = EDevelopmentState.Finished, // TODO: Change this Code = theTeam.ShortName + "." + theDesign.Code, Name = theDesign.Name, PartDesignType = theDesign.PartDesignType, Owner = theTeam, IsPlayable = true }; theTeam.PartDesigns.Add(theNewDesign); teamRepo.Update(theTeam); uow.Commit(); }
/// <summary> /// Creates a new empty team. /// </summary> /// <param name="managerName">Name of the manager.</param> /// <param name="countryName">Name of the country.</param> /// <param name="teamName">Name of the team.</param> /// <param name="teamShortName">Short name of the team.</param> public void CreateEmptyTeam(string managerName, string countryName, string teamName, string teamShortName) { if (string.IsNullOrEmpty(managerName)) { throw new ArgumentNullException("managerName"); } if (string.IsNullOrEmpty(countryName)) { throw new ArgumentNullException("countryName"); } if (string.IsNullOrEmpty(teamName)) { throw new ArgumentNullException("teamName"); } if (string.IsNullOrEmpty(teamShortName)) { throw new ArgumentNullException("teamShortName"); } var playerRepo = this.container.Resolve<IGenericRepository<Player>>(); var countryRepo = this.container.Resolve<ICountryRepository>(); var teamRepo = this.container.Resolve<ITeamRepository>(); var uow = this.container.Resolve<IUnitOfWork>(); // Check the country Country theCountry = countryRepo.GetByName(countryName); if (theCountry == null) { throw new InvalidOperationException("Country not exists."); } // TODO: Unique constraints in team name, team short name, and player name... Player thePlayer = new Player() { Name = managerName, Country = theCountry }; playerRepo.Save(thePlayer); Team theTeam = new Team() { Manager = thePlayer, Name = teamName, ShortName = teamShortName, IsPlayable = true }; theTeam.Vehicles.Add(new Vehicle() { Team = theTeam, VehicleType = EVehicleType.FirstVehicle }); theTeam.Vehicles.Add(new Vehicle() { Team = theTeam, VehicleType = EVehicleType.SecondVehicle }); teamRepo.Save(theTeam); uow.Commit(); }
/// <summary> /// Places a team order. /// </summary> /// <param name="theTeam">The team which made the order.</param> /// <param name="orderTypeValue">The order type.</param> /// <param name="parameters">The parameters of the order.</param> public void PlaceTeamOrder(Team theTeam, EOrderType orderTypeValue, string parameters) { var orderTypeRepo = this.container.Resolve<IOrderTypeRepository>(); OrderType orderType = orderTypeRepo.GetByOrderTypeValue(orderTypeValue); var uow = this.container.Resolve<IUnitOfWork>(); Order order = new Order() { Team = theTeam, OrderType = orderType, Parameters = parameters, DateTime = DateTime.Now, CountdownToProcess = orderType.TimeToProcess }; orderRepo.Save(order); uow.Commit(); }
/// <summary> /// Builds a part from a design. /// </summary> /// <param name="theDesign">The design.</param> /// <param name="theTeam">The team wich is buying the part.</param> /// <returns>The buyed part.</returns> public Part BuyStandardPart(PartDesign theDesign, Team theTeam) { if (theDesign == null) { throw new ArgumentNullException("theDesign"); } if (theTeam == null) { throw new ArgumentNullException("theTeam"); } if (theDesign.BasedOn != null) { throw new InvalidOperationException("Cannot buy a part of this design."); } if (theDesign.Owner != null) { throw new InvalidOperationException("This part is not a standard part."); } var partRepo = this.container.Resolve<IPartRepository>(); var uow = this.container.Resolve<IUnitOfWork>(); // TODO: Filter this from repository (parts by team & design) string newNoCode = theTeam.Parts.Where(x => x.Design.Equals(theDesign)).ToList<Part>().Count.ToString("000", CultureInfo.CurrentCulture); Part theNewPart = new Part(theDesign) { Code = theTeam.ShortName + "." + theDesign.Code + "." + newNoCode, Owner = theTeam, ProductionState = EDevelopmentState.Finished }; theTeam.Parts.Add(theNewPart); partRepo.Save(theNewPart); uow.Commit(); return theNewPart; }
public MountPartDialog(Team theTeam) { InitializeComponent(); this.DataContext = theTeam.Parts.Where(x => x.ProductionState == EDevelopmentState.Finished && x.MountedIn == null).ToList<Part>(); }
/// <summary> /// Removes a team from the system. /// </summary> /// <param name="team">The team to remove.</param> public void DropTeam(Team team) { this.teamAppServices.DropTeam(team); }
private void InitializeTeam(FastTeamData teamData, List<FastPartDesignData> designData) { // Repositories var countriesRepo = this.container.Resolve<ICountryRepository>(); var teamsRepo = this.container.Resolve<ITeamRepository>(); var driversRepo = this.container.Resolve<IDriverRepository>(); var designTypesRepo = this.container.Resolve<IPartDesignTypeRepository>(); var partDesignsRepo = this.container.Resolve<IPartDesignRepository>(); var partsRepo = this.container.Resolve<IPartRepository>(); var playersRepo = this.container.Resolve<IGenericRepository<Player>>(); // Country Country country = countriesRepo.GetByName(teamData.PlayerCountryName); if (country == null) { country = new Country() { Name = teamData.PlayerCountryName }; countriesRepo.Save(country); } // Design Types var designTypes = designTypesRepo.GetAllInDictionary(); // Team Team theTeam = teamsRepo.GetByShortName(teamData.ShortTeamName); if (theTeam == null) { Player thePlayer = new Player() { Name = teamData.ManagerName, Country = country }; playersRepo.Save(thePlayer); theTeam = new Team() { Name = teamData.TeamName, WebName = teamData.WebTeamName, Manager = thePlayer, ShortName = teamData.ShortTeamName }; teamsRepo.Save(theTeam); } // Drivers Driver driver1 = driversRepo.GetByShortName(teamData.Driver1ShortName); if (driver1 == null) { driver1 = new Driver() { Name = teamData.Driver1Name, ShortName = teamData.Driver1ShortName, Owner = theTeam }; driversRepo.Save(driver1); } Driver driver2 = driversRepo.GetByShortName(teamData.Driver2ShortName); if (driver2 == null) { driver2 = new Driver() { Name = teamData.Driver2Name, ShortName = teamData.Driver2ShortName, Owner = theTeam }; driversRepo.Save(driver2); } Driver testDriver = null; if (!String.IsNullOrEmpty(teamData.TestDriverName)) { testDriver = driversRepo.GetByShortName(teamData.TestDriverShortName); if (testDriver == null) { testDriver = new Driver() { Name = teamData.TestDriverName, ShortName = teamData.TestDriverShortName, Owner = theTeam }; driversRepo.Save(testDriver); } } // Part designs IList<PartDesign> designs = new List<PartDesign>(); foreach (var item in designData) { Team t = null; if (item.DesignOwnerShortName == theTeam.Name) { t = theTeam; } else if (!string.IsNullOrEmpty(item.DesignOwnerShortName)) { t = teamsRepo.GetByShortName(item.DesignOwnerShortName); } designs.Add(this.CreateAndAssignPartDesign(item.DesignName, item.DesignShortName, partDesignsRepo, designTypes[item.DesignTypeName], t)); } // Parts foreach (var design in designs) { for (int i = 0; i < 4; i++) { string code = string.Concat(design.Code, ".", i.ToString("000", CultureInfo.CurrentCulture)); if (design.Owner == null || design.Owner.ShortName != theTeam.ShortName) { code = string.Concat(theTeam.ShortName, ".", code); } Part thePart = partsRepo.GetByCode(code); if (thePart == null) { thePart = new Part(design) { Code = code, Owner = theTeam, ProductionState = EDevelopmentState.Finished }; partsRepo.Save(thePart); } if (!theTeam.Parts.Contains(thePart)) { theTeam.Parts.Add(thePart); } } } // CARS if (theTeam.Vehicles.Count < 2) { Vehicle car1 = new Vehicle() { Team = theTeam, Driver = driver1, Number = teamData.Driver1No, VehicleType = EVehicleType.FirstVehicle }; foreach (var kvp in designTypes) { Part part = theTeam.Parts.First(x => x.Design.PartDesignType == kvp.Value && x.MountedIn == null); if (part != null) { car1.WearingParts.Add(part); part.MountedIn = car1; } } theTeam.Vehicles.Add(car1); Vehicle car2 = new Vehicle() { Team = theTeam, Driver = driver2, Number = teamData.Driver2No, VehicleType = EVehicleType.SecondVehicle }; foreach (var kvp in designTypes) { Part part = theTeam.Parts.First(x => x.Design.PartDesignType == kvp.Value && x.MountedIn == null); if (part != null) { car2.WearingParts.Add(part); part.MountedIn = car2; } } theTeam.Vehicles.Add(car2); if (!string.IsNullOrEmpty(teamData.TestDriverName)) { Vehicle testCar = new Vehicle() { Team = theTeam, Driver = testDriver, VehicleType = EVehicleType.Muleto }; foreach (var kvp in designTypes) { Part part = theTeam.Parts.First(x => x.Design.PartDesignType == kvp.Value && x.MountedIn == null); if (part != null) { testCar.WearingParts.Add(part); part.MountedIn = testCar; } } theTeam.Vehicles.Add(testCar); } } }
private PartDesign CreateAndAssignPartDesign(string name, string code, IPartDesignRepository partDesignsRepo, PartDesignType designType, Team theTeam) { PartDesign theDesign = partDesignsRepo.GetByCode(code); if (theDesign == null) { theDesign = new PartDesign() { Name = name, Code = code, PartDesignType = designType, Owner = theTeam, DevelopmentState = EDevelopmentState.Finished }; partDesignsRepo.Save(theDesign); } if (theTeam != null && !theTeam.PartDesigns.Contains(theDesign)) { theTeam.PartDesigns.Add(theDesign); } return theDesign; }
/// <summary> /// Places a team order. /// </summary> /// <param name="theTeam">The team which made the order.</param> /// <param name="orderTypeValue">The order type.</param> /// <param name="parameters">The parameters of the order.</param> public void PlaceTeamOrder(Team theTeam, EOrderType orderTypeValue, string parameters) { OrderingServices orderingSvc = new OrderingServices(); orderingSvc.PlaceTeamOrder(theTeam, orderTypeValue, parameters); }
/// <summary> /// Calculates the team result. /// </summary> /// <param name="team">The team wich results are going to be calculated.</param> /// <param name="grandPrixResult">The grand prix real results.</param> /// <returns>A list of Race Results (one per car).</returns> public IList<RaceResult> CalculateTeamResult(Team team, IList<RaceResult> grandPrixResult) { foreach (Vehicle car in team.Vehicles) { if (this.CheckVehicleToRace(car)) { RaceResult resultCar = this.CalculateCarTime(car, grandPrixResult); grandPrixResult.Add(resultCar); } } // Reorder the results IList<RaceResult> finalResult = grandPrixResult.OrderByDescending(x => x.LapsNo).ThenBy(x => x.Time).ToList<RaceResult>(); // Arrange position fields int pos = 1; foreach (var item in finalResult) { if (item.Time > TimeSpan.FromMilliseconds(0)) { item.Position = pos++; } } // Reorder again return finalResult.OrderByDescending(x => x.LapsNo).ThenBy(x => x.Time).ThenBy(x => x.Position).ToList<RaceResult>(); }
/// <summary> /// Removes a team from the database. /// </summary> /// <param name="team">The team to remove.</param> public void DropTeam(Team team) { if (team == null) { throw new ArgumentNullException("team"); } var teamRepo = this.container.Resolve<ITeamRepository>(); var uow = this.container.Resolve<IUnitOfWork>(); teamRepo.Delete(team); uow.Commit(); }
/// <summary> /// Calculates the team result. /// </summary> /// <param name="team">The team wich results are going to be calculated.</param> /// <param name="grandPrixResult">The grand prix real results.</param> /// <returns>A list of Race Results (one per car).</returns> public IList<RaceResult> CalculateTeamResult(Team team, IList<RaceResult> grandPrixResult) { ResultsServices resSvc = new ResultsServices(); return resSvc.CalculateTeamResult(team, grandPrixResult); }
/// <summary> /// Removes a team from the system. /// </summary> /// <param name="team">The team to remove.</param> public void DropTeam(Team team) { // This order is inmediate!! TeamServices teamSvc = new TeamServices(); teamSvc.DropTeam(team); }