Пример #1
0
        public ActionResult Create(YearViewModel model)
        {
            var events = new List<Event>();
            var currentDate = model.StartDate;
            var index = 0;
            while (currentDate < model.EndDate)
            {
                events.Add(new Event
                {
                    Date = currentDate,
                    EventNumber = index,
                });

                currentDate = currentDate.AddDays(7);
            }

            var scenario = new Scenario();
            if (model.ScenarioId.HasValue)
                scenario = _session.SingleById<Scenario>(model.ScenarioId.Value);
            else
                scenario.Name = model.ScenarioName;

            var year = new Year
            {
                Events = events,
                Name = model.YearName,
                PlayableCategories = _session.Set<Category>().ToList(),
                PlayableRaces = _session.Set<Race>().ToList()

            };
            scenario.Years.Add(year);
            _session.Add(scenario);
            _session.Commit();

            return RedirectToAction("Index");
        }
Пример #2
0
        public ActionResult Update(YearViewModel model)
        {
            var data = _session.SingleById<Year>(model.YearId);

            data.Current = model.Current;

            _session.Commit();

            return RedirectToAction("Update", new { eventId = data.Id });
        }