Exemplo n.º 1
0
        public ActionResult Create()
        {
            CreateWarViewModel model = new CreateWarViewModel();
            model.StartDate = DateTime.Today;

            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult Create(CreateWarViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    War newWar = new War();
                    newWar.EnemyClanName = model.EnemyClanName;
                    newWar.EnemyClanTag = model.EnemyClanTag;
                    newWar.Type = model.WarType;
                    newWar.StartDate = model.StartDate;
                    newWar.FinishedFlag = false;

                    WarManager.Add(newWar);

                    List<WarStat> stats = new List<WarStat>();
                    foreach(string id in model.WarMembers)
                    {
                        int memberId = 0;
                        int.TryParse(id, out memberId);

                        WarStat stat = new WarStat(newWar.ID, memberId);

                        stats.Add(stat);
                    }

                    WarManager.AddStats(stats);
                }
            }
            catch
            {
                return View(new CreateWarViewModel());
            }

            return RedirectToAction("EditMode");
        }