コード例 #1
0
ファイル: PartServices.cs プロジェクト: masuar/BRIATORES
        /// <summary>
        /// Builds a part from a design.
        /// </summary>
        /// <param name="theDesign">The design.</param>
        /// <returns>The new part.</returns>
        public Part BuildPartFromDesign(PartDesign theDesign)
        {
            if (theDesign == null)
            {
                throw new ArgumentNullException("theDesign");
            }

            if (theDesign.BasedOn == null)
            {
                throw new InvalidOperationException("Cannot build from a base design.");
            }

            var partRepo = this.container.Resolve<IPartRepository>();
            var uow = this.container.Resolve<IUnitOfWork>();

            // TODO: Filter this from repository (parts by team & design)
            string newNoCode = theDesign.Owner.Parts.Where(x => x.Design == theDesign).ToList<Part>().Count.ToString("000", CultureInfo.CurrentCulture);

            Part theNewPart = new Part(theDesign)
            {
                Code = theDesign.Code + "." + newNoCode,
                Owner = theDesign.Owner,
                ProductionState = EDevelopmentState.Finished
            };

            theDesign.Owner.Parts.Add(theNewPart);
            partRepo.Save(theNewPart);

            uow.Commit();

            return theNewPart;
        }
コード例 #2
0
ファイル: PartServices.cs プロジェクト: masuar/BRIATORES
        /// <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;
        }
コード例 #3
0
ファイル: PartServices.cs プロジェクト: masuar/BRIATORES
        /// <summary>
        /// Mounts a part in a car.
        /// </summary>
        /// <param name="thePart">The part to mount.</param>
        /// <param name="theCar">The car where the part will be mounted.</param>
        public void Mount(Part thePart, Vehicle theCar)
        {
            if (thePart == null)
            {
                throw new ArgumentNullException("thePart");
            }

            if (theCar == null)
            {
                throw new ArgumentNullException("theCar");
            }

            if (thePart.ProductionState != EDevelopmentState.Finished)
            {
                throw new InvalidOperationException("Part is not finished or is deprecated.");
            }

            if (thePart.MountedIn != null)
            {
                throw new InvalidOperationException("Part is mounted in other vehicle.");
            }

            var carRepo = this.container.Resolve<IVehicleRepository>();
            var uow = this.container.Resolve<IUnitOfWork>();

            // TODO: Filter this in the repository (wearing part by design type)
            if (theCar.WearingParts.Where(x => x.Design.PartDesignType == thePart.Design.PartDesignType).ToList().Count > 0)
            {
                throw new InvalidOperationException("Part type is already mounted.");
            }

            thePart.MountedIn = theCar;
            theCar.WearingParts.Add(thePart);

            carRepo.Update(theCar);

            uow.Commit();
        }
コード例 #4
0
ファイル: PartServices.cs プロジェクト: masuar/BRIATORES
        /// <summary>
        /// Unmounts a part from a car.
        /// </summary>
        /// <param name="thePart">The part to be unmounted.</param>
        public void Unmount(Part thePart)
        {
            if (thePart == null)
            {
                throw new ArgumentNullException("thePart");
            }

            if (thePart.MountedIn == null)
            {
                throw new InvalidOperationException("Part is not mounted.");
            }

            var partRepo = this.container.Resolve<IPartRepository>();
            var uow = this.container.Resolve<IUnitOfWork>();
            thePart.MountedIn.WearingParts.Remove(thePart);
            thePart.MountedIn = null;

            partRepo.Update(thePart);

            uow.Commit();
        }
コード例 #5
0
ファイル: DataInitializator.cs プロジェクト: masuar/BRIATORES
        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);
                }
            }
        }