Exemple #1
0
        /// <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;
        }
        /// <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>
        /// Registers the incidents per design.
        /// </summary>
        /// <param name="design">The design.</param>
        /// <param name="vehiclesMountingThisDesign">The vehicles mounting this design.</param>
        public void RegisterIncidentsPerDesign(PartDesign design, IList<Vehicle> vehiclesMountingThisDesign)
        {
            if (this.probs.ContainsKey(design.PartDesignType.Name))
            {
                this.probs[design.PartDesignType.Name][0] = vehiclesMountingThisDesign.Count;

                foreach (var veh in vehiclesMountingThisDesign)
                {
                    RaceResult incidentedCarResult = this.grandPrixResult.Where(x => x.Vehicle.Id == veh.Id && !string.IsNullOrEmpty(x.Description)).FirstOrDefault();
                    if (incidentedCarResult != null)
                    {
                        if (this.IsDesignTypeRelatedToIncident(design.PartDesignType.Name, incidentedCarResult.Description))
                        {
                            this.probs[design.PartDesignType.Name][1]++;
                        }
                    }
                }
            }
        }
Exemple #4
0
        /// <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;
        }
        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;
        }
Exemple #6
0
 private PartDesign GetBaseDesign(PartDesign design)
 {
     if (design.BasedOn == null)
     {
         return design;
     }
     else
     {
         return this.GetBaseDesign(design.BasedOn);
     }
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Part"/> class.
 /// </summary>
 /// <param name="design">The design.</param>
 public Part(PartDesign design)
 {
     this.design = design;
 }