コード例 #1
0
        public static AddressProfiles.AddressProfile GetBaseAddress(MilitaryBranch branch, string hq)
        {
            var a = new AddressProfiles.AddressProfile();

            var raw = File.ReadAllText("config/military_bases.json");
            var o   = JsonConvert.DeserializeObject <MilitaryBases.BaseManager>(raw);

            var b      = o.Branches.FirstOrDefault(x => x.Name == branch.ToString());
            var myBase = b.Bases.FirstOrDefault(x => x.Name.Equals(hq, StringComparison.InvariantCultureIgnoreCase));

            if (myBase == null)
            {
                myBase = o.Branches.FirstOrDefault(x => x.Name == branch.ToString())?.Bases.RandomElement();
            }

            if (myBase == null)
            {
                return(null);
            }

            a.AddressType = "Base";
            a.Name        = myBase.Name;
            if (myBase.Streets.Any())
            {
                a.Address1 = myBase.Streets.RandomElement();
            }
            if (string.IsNullOrEmpty(a.Address1))
            {
                a.Address1 = Address.GetStreetAddress();
            }
            a.City       = myBase.City;
            a.State      = myBase.State;
            a.PostalCode = myBase.PostalCode;
            if (string.IsNullOrEmpty(a.State))
            {
                a.State = Address.GetUSStateAbbreviation();
            }
            if (string.IsNullOrEmpty(a.City))
            {
                var cityAndZip = Address.GetCityAndZipFromStateAbbreviation(a.State);
                a.City       = cityAndZip["City"];
                a.PostalCode = cityAndZip["ZipCode"];
            }
            return(a);
        }
コード例 #2
0
        public static MilitaryRank.Branch.Rank GetRankByBranch(MilitaryBranch branch)
        {
            var ranks = new List <MilitaryRank.Branch.Rank>();
            var mil   = GetAllEx();

            foreach (var b in mil.Branches.Where(x => x.Name == branch.ToString()))
            {
                ranks.AddRange(b.Ranks);
            }

            return(GetRank(ranks));
        }
コード例 #3
0
        public MilitaryUnitService(MilitaryBranch branch, MilitaryUnit units)
        {
            var unit = units.Sub.ToList().FirstOrDefault(x => x.Nick == branch.ToString());

            this.Unit     = units.Clone();
            this.Unit.Sub = null;

            if (unit != null)
            {
                var currentUnit = unit.Clone();
                var list        = new List <MilitaryUnit.Unit>();

                while (currentUnit != null)
                {
                    if (currentUnit.Sub == null)
                    {
                        break;
                    }

                    currentUnit = GetUnit(currentUnit);
                    list.Add(currentUnit);
                }

                list.Reverse();
                List <MilitaryUnit.Unit> previous = null;
                foreach (var item in list)
                {
                    if (previous == null)
                    {
                        previous = new List <MilitaryUnit.Unit>();
                    }

                    previous = SetUnit(previous, new List <MilitaryUnit.Unit> {
                        item
                    });
                }

                this.Unit.Sub = previous;
            }

            this.Unit.Country = units.Country;
        }
コード例 #4
0
        public static IEnumerable <MilitaryUnit.Unit> GetAllByServiceBranch(MilitaryBranch branch)
        {
            var o = GetAllEx();

            return(o.Sub.Where(x => x.Nick == branch.ToString()));
        }