public SeriesViewModel GetNewSeriesViewModel(int clubId)
        {
            var model = new SeriesViewModel();

            model.Club = _clubRepository.GetClubById(clubId);
            model.AllClasses = _classRepository.GetAllClasses();

            return model;
        }
        public SeriesViewModel GetEditSeriesViewModel(int seriesId)
        {
            var model = new SeriesViewModel();

            var series = _seriesRepository.GetSeriesById(seriesId);

            model.SeriesId = series.SeriesId;
            model.Name = series.Name;
            model.BeginDate = series.BeginDate;
            model.Club = series.Club;

            model.AllClasses = _classRepository.GetAllClasses();

            model.SelectedClasses = new int[series.SeriesClasses.Count];

            for (int i = 0; i < series.SeriesClasses.Count; i ++)
            {
                model.SelectedClasses[i] = series.SeriesClasses.ToArray()[i].ClassId;
            }

            return model;
        }
        public SeriesViewModel UpdateSeries(SeriesViewModel model)
        {
            var series = _seriesRepository.GetSeriesById(model.SeriesId);

            series.Name = model.Name;
            series.BeginDate = model.BeginDate;

            IList<SeriesClass> newClasses = null;

            if (model.SelectedClasses != null && model.SelectedClasses.Length > 0)
            {
                //series = _seriesRepository.DeleteAllSeriesClasses(series);

                foreach (var classId in model.SelectedClasses)
                {
                    var classInSeries = new SeriesClass { SeriesId = model.SeriesId, ClassId = classId };

                    if (newClasses == null)
                    {
                        newClasses = new List<SeriesClass>();
                    }

                    newClasses.Add(classInSeries);
                }
            }

            _seriesRepository.UpdateSeries(series, newClasses);

            return model;
        }
        public SeriesViewModel SaveNewSeries(SeriesViewModel model)
        {
            var series = new Series
                           	{
                           		Name = model.Name,
                                BeginDate = model.BeginDate,
                           		ClubId = model.Club.ClubId,
                                DateCreated = DateTime.Now
                           	};

            if (model.SelectedClasses != null && model.SelectedClasses.Length > 0)
            {
                foreach (var classId in model.SelectedClasses)
                {
                    var classInSeries = new SeriesClass {SeriesId = model.SeriesId, ClassId = classId};

                    if (series.SeriesClasses == null)
                    {
                        series.SeriesClasses = new EntityCollection<SeriesClass>();
                    }

                    series.SeriesClasses.Add(classInSeries);
                }
            }

            _seriesRepository.SaveNewSeries(series);

            model.SeriesId = series.SeriesId;

            return model;
        }