コード例 #1
0
        public ActionResult Recruit(ArmyRecruitViewModel vmAR)
        {
            string message = Manager.RecruitTroops(vmAR.Id, vmAR.HAmount);

            TempData["Message"] = message;
            return(RedirectToAction("ArmyRecruit"));
        }
コード例 #2
0
ファイル: Manager.cs プロジェクト: Freamy/EnCoOrszagos
        public static ArmyRecruitViewModel MakeArmyRecruitViewModel()
        {
            using (var context = new ApplicationDbContext())
            {
                int activeCountryId = context.Users.First(c => c.UserName == System.Web.HttpContext.Current.User.Identity.Name).Country.Id;


                List <UnitType>          unitList = context.UnitTypes.ToList <UnitType>();
                List <UnitTypeViewModel> vmUnit   = new List <UnitTypeViewModel>();

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

                if (country.StandingForce.FirstOrDefault(m => m.Id == 1) == null)
                {
                    List <UnitType> types = context.UnitTypes.ToList <UnitType>();

                    foreach (var type in types)
                    {
                        Manager.RecruitTroops(type.Id, 0);
                    }
                }


                int         sum      = 0;
                List <Army> standing = country.StandingForce.ToList();
                vmUnit = context.UnitTypes.Select(m => new UnitTypeViewModel()
                {
                    Name        = m.Name,
                    Payment     = m.Payment,
                    Attack      = m.Attack,
                    Defense     = m.Defense,
                    Cost        = m.Cost,
                    Upkeep      = m.Upkeep,
                    Description = m.Description,
                    Id          = m.Id,
                    //Size = context.Armies.FirstOrDefault(k => k.Type.Id == m.Id).Size
                }).ToList();

                foreach (var item in vmUnit)
                {
                    item.Size = country.StandingForce.FirstOrDefault(m => m.Type.Id == item.Id).Size;
                }

                sum = country.StandingForce.Sum(m => m.Size);

                ArmyRecruitViewModel vmAR = new ArmyRecruitViewModel()
                {
                    Types         = vmUnit,
                    OccupiedSpace = sum,
                    AllSpace      = context.Buildings.Where(m => m.Country.Id == activeCountryId).FirstOrDefault(m => m.Blueprint.Name == "Barrack") != null
                        ? context.Buildings.Where(m => m.Country.Id == activeCountryId).FirstOrDefault(m => m.Blueprint.Name == "Barrack").NumberOfBuildings * 200 : 0
                };
                vmAR.Gold   = context.Countries.First(m => m.Id == activeCountryId).Gold;
                vmAR.Potato = context.Countries.First(m => m.Id == activeCountryId).Potato;
                return(vmAR);
            }
        }