示例#1
0
        public static AssaultViewModel MakeAssaultViewModel()
        {
            using (var context = new ApplicationDbContext())
            {
                int activeCountryId = context.Users.First(c => c.UserName == System.Web.HttpContext.Current.User.Identity.Name).Country.Id;
                AssaultViewModel vmAssault = new AssaultViewModel();

                vmAssault.OwnName = context.Countries.FirstOrDefault(m => m.Id == activeCountryId).Name;

                List<Country> countries = new List<Country>() ;
                foreach (var item in context.Countries.ToList<Country>())
                {
                        Country c = new Country();
                        c.Id = item.Id;
                        c.Name = item.Name;
                        countries.Add(c);
                }

                vmAssault.Countries = countries;

                Country country = context.Countries.First(m => m.Id == activeCountryId);

                List<Army> armies = new List<Army>();

                armies = country.StandingForce.Select(m => new Army()
                {
                    Size = m.Size,
                    Type = new UnitType()
                    {
                        Name = m.Type.Name,
                        Attack = m.Type.Attack,
                        Defense = m.Type.Defense,
                        Description = m.Type.Description
                    }
                }).ToList();
                /*
                foreach (var item in country.StandingForce.ToList<Army>())
                {
                    Army army = new Army();
                    army.Size = item.Size;
                    UnitType ut = new UnitType();
                    ut.Name = item.Type.Name;
                    ut.Attack = item.Type.Attack;
                    ut.Defense = item.Type.Defense;
                    ut.Description = item.Type.Description;
                    army.Type = ut;
                    armies.Add(army);
                }*/

               // vmAssault.Armies = country.StandingForce.ToList<Army>();
                vmAssault.Armies = armies;

                List<AssaultsCollectModel> cmAssault = new List<AssaultsCollectModel>();

                foreach (var item in country.Assaults.ToList<Assault>())
                {
                    AssaultsCollectModel assault = new AssaultsCollectModel();

                    Country c = new Country()
                    {
                        Id = item.Target.Id,
                        Name = item.Target.Name
                    };

                    assault.Country = c;

                    List<Force> newForces = new List<Force>();

                    newForces = item.Forces.Select(
                        m => new Force(){
                            Size = m.Size,
                            Type = new UnitType()
                            {
                                Id = m.Type.Id,
                                Name = m.Type.Name,
                            }
                        }
                     ).ToList();

                    /*foreach (var f in item.Forces.ToList<Force>())
                    {
                        Force newForce = new Force()
                        {
                            Size = f.Size
                        };
                        newForce.Size = f.Size;
                        UnitType newType = new UnitType();
                        newType.Id = f.Type.Id;
                        newType.Name = f.Type.Name;
                        newForce.Type = newType;
                        newForces.Add(newForce);
                    }*/

                    assault.Forces = newForces;
                    cmAssault.Add(assault);
                }

                vmAssault.Assaults = cmAssault;
                return vmAssault;
            }
        }
示例#2
0
        public static Country GetNewCountry(RegisterViewModel model)
        {
            using (var context = new ApplicationDbContext())
            {
                Country country = new Country()
                {
                    Gold = 10000,
                    Potato = 10000,
                    Name = model.CountryName,

                };
                return country;
            }
        }