Example #1
0
        public StandingsViewModel GetStandingsForSeries(Series currentSeries)
        {
            var model = new StandingsViewModel();

            foreach (var seriesClass in currentSeries.SeriesClasses)
            {
                var seriesClassResults = _resultService.GetResultsForClassBySeriesId(currentSeries.SeriesId, seriesClass.ClassId);

                var standingsGroup = new StandingsGroupViewModel();

                standingsGroup.ClassId = seriesClass.ClassId;
                standingsGroup.ClassName = seriesClass.Class.Name;

                foreach(var result in seriesClassResults)
                {
                    var item = new StandingsItemViewModel();

                    item.Driver = result.Driver;
                    item.TotalPoints = seriesClassResults.Where(r => r.DriverId == result.DriverId).Sum(p => p.PointsEarned).GetValueOrDefault(0);

                    if(standingsGroup.StandingsItems == null)
                    {
                        standingsGroup.StandingsItems = new List<StandingsItemViewModel>();
                    }

                    StandingsItemViewModel existingItem = null;

                    if (standingsGroup.StandingsItems.Where(i => i.Driver == item.Driver).Count() > 0)
                    {
                        existingItem = standingsGroup.StandingsItems.Single(i => i.Driver == item.Driver);
                    }

                    if(existingItem == null)
                    {
                        standingsGroup.StandingsItems.Add(item);
                        //existingItem.TotalPoints += item.TotalPoints;
                    }
                    //else
                    //{
                    //    standingsGroup.StandingsItems.Add(item);
                    //}
                }

                if(model.Standings == null)
                {
                    model.Standings = new List<StandingsGroupViewModel>();
                }

                model.Standings.Add(standingsGroup);
            }

            model.SelectedSeriesId = currentSeries.SeriesId;

            return model;
        }
        public Series SaveNewSeries(Series series)
        {
            using (var connection = new EntityConnection("name=CoreContainer"))
            {
                _core = new CoreContainer(connection);

                _core.Series.AddObject(series);
                _core.SaveChanges();
            }

            return series;
        }
        public Series DeleteAllSeriesClasses(Series series)
        {
            foreach (var seriesClass in series.SeriesClasses)
            {
                using (var connection = new EntityConnection("name=CoreContainer"))
                {
                    _core = new CoreContainer(connection);

                    string query = string.Format("delete from SeriesClass where SeriesClassId = {0}", seriesClass.SeriesClassId);

                    _core.ExecuteStoreCommand(query);
                }
            }

            return series;
        }
        public Series GetSeriesById(int seriesId)
        {
            var series = new Series();

            using (var connection = new EntityConnection("name=CoreContainer"))
            {
                _core = new CoreContainer(connection);

                series = _core.Series
                        .Include("Club")
                        .Include("SeriesClasses")
                        .Where(s => s.SeriesId == seriesId)
                        .FirstOrDefault();
            }

            return series;
        }
        public Series UpdateSeries(Series series, IList<SeriesClass> newClasses)
        {
            using (var connection = new EntityConnection("name=CoreContainer"))
            {
                _core = new CoreContainer(connection);

                _core.Series.Attach(_core.Series.Include("SeriesClasses").Single(s => s.SeriesId == series.SeriesId));

                _core.Series.ApplyCurrentValues(series);

                if (series.SeriesClasses != null && series.SeriesClasses.Count > 0)
                {
                    foreach (var oldClass in series.SeriesClasses)
                    {
                        string query = string.Format("delete from SeriesClass where SeriesClassId = {0}", oldClass.SeriesClassId);

                        _core.ExecuteStoreCommand(query);
                    }
                }

                var saveSeries = _core.Series.Single(s => s.SeriesId == series.SeriesId);

                foreach (var selectedClass in newClasses)
                {
                    saveSeries.SeriesClasses.Add(new SeriesClass{ClassId = selectedClass.ClassId, SeriesId = selectedClass.SeriesId});
                }

                _core.SaveChanges();
            }

            return series;
        }
Example #6
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Series EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSeries(Series series)
 {
     base.AddObject("Series", series);
 }
Example #7
0
 /// <summary>
 /// Create a new Series object.
 /// </summary>
 /// <param name="seriesId">Initial value of the SeriesId property.</param>
 /// <param name="clubId">Initial value of the ClubId property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="dateCreated">Initial value of the DateCreated property.</param>
 /// <param name="beginDate">Initial value of the BeginDate property.</param>
 public static Series CreateSeries(global::System.Int32 seriesId, global::System.Int32 clubId, global::System.String name, global::System.DateTime dateCreated, global::System.DateTime beginDate)
 {
     Series series = new Series();
     series.SeriesId = seriesId;
     series.ClubId = clubId;
     series.Name = name;
     series.DateCreated = dateCreated;
     series.BeginDate = beginDate;
     return series;
 }
Example #8
0
        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;
        }