예제 #1
0
        /// <summary>
        /// Methode zum Ermitteln einer FussbalWM
        /// </summary>
        public static FussballWM GetWM()
        {
            using (var context = new WM2010Entities())
            {
                var wm = (from w in context.FussballWM
                          select w).First();

                if (wm == null)
                    throw new ObjectNotFoundException("wm");

                return wm;
            }
        }
예제 #2
0
        /// <summary>
        /// Ermittelt alle Begegnungen einer Gruppe
        /// </summary>
        /// <returns></returns>
        public Begegnung[] GetBegegnungen(int gruppenId)
        {
            var games = new List<Spiel>();
            var begegnungen = new List<Begegnung>();

            using (var context = new WM2010Entities())
            {
                var mannschaften = GetMannschaften(gruppenId);

                foreach (var m in mannschaften)
                {
                    var spiele = (from s in context.Spiel
                                  where s.Mannschaft1Id == m.MannschaftId || s.Mannschaft2Id == m.MannschaftId
                                  select s).ToList();
                    foreach (var spiel in spiele)
                    {
                        if (!games.Contains(spiel))
                        {
                            spiel.SpielOrtReference.Load();
                            games.Add(spiel);
                        }
                    }
                }

                foreach (var game in games)
                {
                    var begegnung = new Begegnung();

                    var m1 = (from m in mannschaften
                              where game.Mannschaft1Id == m.MannschaftId
                              select m).FirstOrDefault();
                    var m2 = (from m in mannschaften
                              where game.Mannschaft2Id == m.MannschaftId
                              select m).FirstOrDefault();

                    if (m1 != null && m2 != null)
                    {
                        begegnung.Spiel = game;
                        begegnung.Mannschaft1Fahne = m1.Fahne;
                        begegnung.Mannschaft1Name = m1.Land;

                        begegnung.Mannschaft2Fahne = m2.Fahne;
                        begegnung.Mannschaft2Name = m2.Land;

                        begegnungen.Add(begegnung);
                    }
                }

                return begegnungen.ToArray();
            }
        }
예제 #3
0
        /// <summary>
        /// Methode zum Erstellen einer FussballWM
        /// </summary>
        public static FussballWM CreateWM(FussballWM wm)
        {
            if (wm == null)
                throw new ArgumentNullException("wm");

            using (var context = new WM2010Entities())
            {
                context.AddToFussballWM(wm);
                context.SaveChanges();

                context.Refresh(RefreshMode.StoreWins, wm);
                return wm;
            }

        }
예제 #4
0
        /// <summary>
        /// Methode zum Aendern einer FussballWM
        /// </summary>
        public static FussballWM UpdateWM(FussballWM wm)
        {
            if (wm == null)
                throw new ArgumentNullException("wm");

            using (var context = new WM2010Entities())
            {
                var update = CqFussballWM.Invoke(context, wm.FussballWMId);
                if (update == null)
                    throw new ObjectNotFoundException("FussballWM not found");

                context.ApplyPropertyChanges(update.EntityKey.EntitySetName, wm);
                context.SaveChanges();

                context.Refresh(RefreshMode.StoreWins, wm);
                return wm;
            }
        }
예제 #5
0
        /// <summary>
        /// Methode zum Ermitteln eines SpielOrtes
        /// </summary>
        public static SpielOrt GetSpielOrt(int spielOrtId)
        {
            if (spielOrtId < 0)
                throw new ArgumentNullException("spielOrtId");

            using (var context = new WM2010Entities())
            {
                var so = CqSpielOrt.Invoke(context, spielOrtId);
                if (so == null)
                    throw new ObjectNotFoundException("SpielOrt");

                return so;
            }
        }
예제 #6
0
        /// <summary>
        /// Methode zum Aendern eines SpielOrtes
        /// </summary>
        public static SpielOrt UpdateSpielOrt(SpielOrt spielOrt)
        {
            if (spielOrt == null)
                throw new ArgumentNullException("spielOrt");

            using (var context = new WM2010Entities())
            {
                var so = CqSpielOrt.Invoke(context, spielOrt.SpielOrtId);

                context.ApplyPropertyChanges(so.EntityKey.EntitySetName, spielOrt);
                context.SaveChanges();
                context.Refresh(RefreshMode.StoreWins, spielOrt);
                return spielOrt;
            }
        }
예제 #7
0
        /// <summary>
        /// Methode zum Erstellen eines SpielOrtes
        /// </summary>
        public static SpielOrt CreateSpielOrt(SpielOrt spielOrt)
        {
            if (spielOrt == null)
                throw new ArgumentNullException("spielOrt");

            using (var context = new WM2010Entities())
            {
                context.AddToSpielOrt(spielOrt);
                context.SaveChanges();
                context.Refresh(RefreshMode.StoreWins, spielOrt);

                return spielOrt;
            }
        }
예제 #8
0
        /// <summary>
        /// Aendert eine Spielposition 
        /// </summary>
        public static SpielPosition UpdateSpielPosition(SpielPosition position)
        {
            if (position == null)
                throw new ArgumentNullException("position");

            using (var context = new WM2010Entities())
            {
                var sp = CqSpielPosition.Invoke(context, position.SpielPositionId);
                if (sp == null)
                    throw new ObjectNotFoundException("spielposition");

                context.ApplyPropertyChanges(sp.EntityKey.EntitySetName, position);
                context.SaveChanges();
                context.Refresh(RefreshMode.StoreWins, position);
                return position;
            }
        }
예제 #9
0
        /// <summary>
        /// Ermittelt die Spielposition eines Spielers
        /// </summary>
        public static SpielPosition GetSpielPosition(int positionId)
        {
            if (positionId < 0)
                throw new ArgumentNullException("positionId");

            using (var context = new WM2010Entities())
            {
                var position = CqSpielPosition.Invoke(context, positionId);
                if (position == null)
                    throw new ObjectNotFoundException("spielposition");

                return position;
            }
        }
예제 #10
0
        /// <summary>
        /// Methode zum Erstellen einer Gruppe
        /// </summary>
        public static Gruppe CreateGruppe(Gruppe gruppe)
        {
            if (gruppe == null)
                throw new ArgumentNullException("gruppe");

            using (var context = new WM2010Entities())
            {
                context.AddToGruppe(gruppe);
                context.SaveChanges();

                context.Refresh(RefreshMode.StoreWins, gruppe);
            }
            return gruppe;
        }
예제 #11
0
        /// <summary>
        /// Methode zum Aendern eines Spiels
        /// </summary>
        public static Spiel UpdateSpiel(Spiel spiel)
        {
            if (spiel == null)
                throw new ArgumentNullException("spiel");

            using (var context = new WM2010Entities())
            {
                var so = CqSpiel.Invoke(context, spiel.Id);

                if (so == null)
                    return null;

                context.ApplyPropertyChanges(so.EntityKey.EntitySetName, spiel);
                context.SaveChanges();
                context.Refresh(RefreshMode.StoreWins, so);

                so.SpielOrtReference.Load();
                return so;
            }
        }
예제 #12
0
        /// <summary>
        /// Ermittelt Spieler aus einer Mannschaft
        /// </summary>
        public static Spieler[] GetSpielerFromMannschaft(int mannschaftsId)
        {
            if (mannschaftsId < 0)
                throw new ArgumentNullException("mannschaftsId");

            using (var context = new WM2010Entities())
            {
                var spieler = (from s in context.Spieler
                               where s.Mannschaft.MannschaftId == mannschaftsId
                               select s).ToArray();

                return spieler;
            }
        }
예제 #13
0
        /// <summary>
        /// Methode zum Erstellen eines Spielers
        /// </summary>
        public static Spieler CreateSpieler(Spieler spieler)
        {
            if (spieler == null)
                throw new ArgumentNullException("spieler");

            using (var context = new WM2010Entities())
            {
                context.AddToSpieler(spieler);
                context.SaveChanges();

                context.Refresh(RefreshMode.StoreWins, spieler);
            }
            return spieler;
        }
예제 #14
0
        /// <summary>
        /// Ermittelt einen Spieler anhand der Id
        /// </summary>
        public static Spieler GetSpieler(int spielerId)
        {
            if (spielerId < 0)
                throw new ArgumentNullException("spielerId");

            using (var context = new WM2010Entities())
            {
                var spieler = CqSpieler.Invoke(context, spielerId);

                if (spieler == null)
                    throw new ObjectNotFoundException("spieler");

                return spieler;
            }
        }
예제 #15
0
        /// <summary>
        /// Methode zum Ermitteln von Gruppen
        /// </summary>
        public static Gruppe[] GetGruppen()
        {

            using (var context = new WM2010Entities())
            {
                var gruppen = (from g in context.Gruppe
                               select g).ToArray();

                return gruppen;
            }
        }
예제 #16
0
        /// <summary>
        /// Methode zum Ermitteln einer Gruppe
        /// </summary>
        public static Gruppe GetGruppe(int id)
        {
            if (id < 0)
                throw new ArgumentNullException("id");

            using (var context = new WM2010Entities())
            {
                var result = CqGruppe(context, id);

                if (result == null)
                    throw new ObjectNotFoundException("gruppe");

                return result;
            }
        }
예제 #17
0
        public static Gruppe UpdateGruppe(Gruppe gruppe)
        {
            if (gruppe == null)
                throw new ArgumentNullException("gruppe");

            using (var context = new WM2010Entities())
            {
                var g = CqGruppe.Invoke(context, gruppe.GruppeId);
                context.ApplyPropertyChanges(g.EntityKey.EntitySetName, gruppe);
                context.SaveChanges();
                context.Refresh(RefreshMode.StoreWins, gruppe);
                return gruppe;
            }
        }
예제 #18
0
        /// <summary>
        /// Methode zum Ermitteln von  Mannschaften
        /// </summary>
        public static Mannschaft[] GetMannschaften()
        {
            using (var context = new WM2010Entities())
            {
                var result = (from m in context.Mannschaft
                              select m).ToArray();

                return result;
            }
        }
예제 #19
0
        /// <summary>
        /// Ermittelt alle Begegnungen aus einem Zeitraum fuer die Finalrunden
        /// </summary>
        /// <returns></returns>
        public Spiel[] GetFinalrundenSpiele(DateTime startDate, DateTime endDate)
        {
            endDate = endDate.AddDays(1);

            using (var context = new WM2010Entities())
            {
                var result = (from g in context.Spiel
                              where g.DatumUhrzeit >= startDate && g.DatumUhrzeit <= endDate
                              select g).ToArray();

                foreach (var r in result)
                {
                    r.SpielOrtReference.Load();
                }

                return result;
            }
        }
예제 #20
0
        /// <summary>
        /// Methode zum Ermitteln eines Spiel
        /// </summary>
        public static Spiel GetSpiel(int mannschaft1Id, int mannschaft2Id)
        {
            using (var context = new WM2010Entities())
            {
                var game = (from s in context.Spiel
                            where s.Mannschaft1Id == mannschaft1Id && s.Mannschaft2Id == mannschaft2Id
                            select s).FirstOrDefault();
                game.SpielOrtReference.Load();

                return game;
            }
        }
예제 #21
0
        /// <summary>
        /// Methode zum Ermitteln einer Mannschaft
        /// </summary>
        public static Mannschaft GetMannschaft(int id)
        {
            if (id <= 0)
                throw new ArgumentNullException("id");

            using (var context = new WM2010Entities())
            {
                var mannschaft = CqMannschaft.Invoke(context, id);

                if (mannschaft == null)
                    throw new ObjectNotFoundException("mannschaft");

                return mannschaft;
            }
        }
예제 #22
0
        /// <summary>
        /// Methode zum Loeschen eines Spiels
        /// </summary>
        public static void DeleteSpiel(int spielId)
        {
            if (spielId < 0)
                throw new ArgumentNullException("spielId");

            using (var context = new WM2010Entities())
            {
                var so = CqSpiel.Invoke(context, spielId);
                if (so == null)
                    throw new ObjectNotFoundException("Spiel");

                context.DeleteObject(so);
                context.SaveChanges();
            }
        }
예제 #23
0
        /// <summary>
        /// Methode zum Aendern einer Mannschaft
        /// </summary>
        public static Mannschaft UpdateMannschaft(Mannschaft mannschaft)
        {
            if (mannschaft == null)
                throw new ArgumentNullException("mannschaft");


            using (var context = new WM2010Entities())
            {
                var m = CqMannschaft.Invoke(context, mannschaft.MannschaftId);
                

                context.ApplyPropertyChanges(m.EntityKey.EntitySetName, mannschaft);
                context.SaveChanges();

                context.Refresh(RefreshMode.StoreWins, m);

                return m;
            }
        }
예제 #24
0
        /// <summary>
        /// Ermittelt Finalrundenspiel anhand des Datums
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public Spiel GetFinalrundenSpiel(DateTime dateTime)
        {
            using (var context = new WM2010Entities())
            {
                var result = (from g in context.Spiel
                              where g.DatumUhrzeit == dateTime
                              select g).FirstOrDefault();
                if (result == null)
                    return null;

                result.SpielOrtReference.Load();

                return result;
            }
        }
예제 #25
0
        /// <summary>
        /// Aendert einen Spieler
        /// </summary>
        public static Spieler UpdateSpieler(Spieler spieler)
        {
            if (spieler == null)
                throw new ArgumentNullException("spieler");

            using (var context = new WM2010Entities())
            {
                var s = CqSpieler.Invoke(context, spieler.SpielerId);
                if (s == null)
                    throw new ObjectNotFoundException("spieler");

                context.ApplyPropertyChanges(s.EntityKey.EntitySetName, spieler);
                context.SaveChanges();
                context.Refresh(RefreshMode.StoreWins, spieler);

                return spieler;
            }
        }
예제 #26
0
        /// <summary>
        /// 
        /// </summary>
        public static SpielPosition CreateSpielPosition(SpielPosition position)
        {
            if (position == null)
                throw new ArgumentNullException("position");

            using (var context = new WM2010Entities())
            {
                context.AddToSpielPosition(position);
                context.SaveChanges();
            }
            return position;

        }
예제 #27
0
        /// <summary>
        /// Methode zum Erstellen einer Mannschaft
        /// </summary>
        public static Mannschaft CreateMannschaft(Mannschaft mannschaft)
        {
            if (mannschaft == null)
                throw new ArgumentNullException("mannschaft");


            using (var context = new WM2010Entities())
            {
                context.AddToMannschaft(mannschaft);
                //context.Detach(mannschaft.Gruppe);

                context.SaveChanges();
                context.Refresh(RefreshMode.StoreWins, mannschaft);
            }

            return mannschaft;
        }