Exemplo n.º 1
0
        public bool connect(string pseudo, string password)
        {
            bool connected = false;
            using (var db = new bowlingEntities())
            {
                try
                {
                    string pwd = utils.CalculateMD5Hash(password);
                    staff user = (from s in db.staffs
                                  where s.Pseudo == pseudo
                                  && s.Password == pwd
                                  select s).Single();
                    if (user != null)
                        connected = true;
                    else
                        connected = false;
                }
                catch (Exception e)
                {
                    throw new Exception("Error", e);
                }

                return connected;
            }
        }
Exemplo n.º 2
0
 public game getCurrentGame()
 {
     using (var db = new bowlingEntities())
     {
         if (!this.isAvalaible())
             return db.games.Where(x => x.State == "in progress" && x.Lane_id == this.Id).SingleOrDefault();
         else
             return null;
     }
 }
Exemplo n.º 3
0
 public void deletePlayer()
 {
     using (var db = new bowlingEntities())
     {
         this.game.players.Remove(this);
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("Error", e);
         }
     }
 }
Exemplo n.º 4
0
 public void addPlayer(player p)
 {
     using (var db = new bowlingEntities())
     {
         this.game.players.Add(p);
         try
         {
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("Error", e);
         }
     }
 }
Exemplo n.º 5
0
 public void cancelGame(game g)
 {
     using (var db = new bowlingEntities())
     {
         try
         {
             game game = db.games.Find(g.Id);
             game.State = "canceled";
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("Error", e);
         }
     }
 }
Exemplo n.º 6
0
 public void addPlayer(game g, player p)
 {
     using (var db = new bowlingEntities())
     {
         try
         {
             game game = db.games.Find(g.Id);
             game.players.Add(p);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("Error", e);
         }
     }
 }
Exemplo n.º 7
0
        public void assignReservation()
        {
            using (bowlingEntities db = new bowlingEntities())
            {
                lane lane = (from l in db.lanes
                             join g in db.games on l.Id equals g.Lane_id
                             where g.State != "finished"
                             select l).SingleOrDefault();

                db.games.Attach(this);
                db.Entry(this).State = EntityState.Modified;

                if (lane != null)
                    this.Lane_id = lane.Id;
                else
                    this.Lane_id = (from l in db.lanes select l).SingleOrDefault().Id;
            }
        }
Exemplo n.º 8
0
        public game createGame()
        {
            bowlingEntities db = new bowlingEntities();
            game g = new game();
            g.State = "pending";
            try
            {
                db.games.Add(g);
                db.SaveChanges();

            }
            catch (Exception e)
            {
                throw new Exception("Error", e);
            }

            return g;
        }
Exemplo n.º 9
0
        public void assignToLane()
        {
            using (var db = new bowlingEntities())
            {
                lane lane = (from l in db.lanes
                             where l.State == "available"
                             select l).SingleOrDefault();

                db.games.Attach(this);
                db.Entry(this).State = EntityState.Modified;

                if (lane != null)
                {
                    this.Lane_id = lane.Id;
                }
                else
                {
                    this.assignReservation();
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 10
0
        public game createGame()
        {
            using (var db = new bowlingEntities())
            {
                db.players.Attach(this);
                db.Entry(this).State = EntityState.Modified;

                game game = new game();
                game.players.Add(this);

                try
                {
                    db.games.Add(game);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    throw new Exception("Error", e);
                }

                return game;
            }
        }