Ejemplo n.º 1
0
        public void RevokeAnswer(int roomNumber, string answer)
        {
            var db = new AppDbContext();
            var room = FindRoom(roomNumber, db);

            var userID = Context.User.Identity.Name;
            ClearMyAnswers(db, room, userID);
            db.SaveChanges();

            UpdateTotaling(room);
        }
Ejemplo n.º 2
0
        public void Reset(int roomNumber)
        {
            var db = new AppDbContext();
            var room = FindRoom(roomNumber, db);
            room.Answers.ToList().ForEach(a =>
            {
                db.Answers.Remove(a);
            });
            db.SaveChanges();

            Clients.Group(roomNumber.ToString()).Reset();
        }
Ejemplo n.º 3
0
        public void PostAnswer(int roomNumber, string answer)
        {
            var db = new AppDbContext();
            var room = FindRoom(roomNumber, db);

            var userID = Context.User.Identity.Name;
            ClearMyAnswers(db, room, userID);

            room.Answers.Add(new Answer
            {
                AnsweredUserID = userID,
                ChosedOptionText = answer
            });
            db.SaveChanges();

            UpdateTotaling(room);
        }
Ejemplo n.º 4
0
        public object EnterRoom(int roomNumber)
        {
            Groups.Add(Context.ConnectionId, roomNumber.ToString());

            var db = new AppDbContext();
            var room = FindRoom(roomNumber, db);
            UpdateTotaling(room);

            var userID = Context.User.Identity.Name;
            var myAnswer = room.Answers
                .FirstOrDefault(a => a.AnsweredUserID == userID) ?? new Answer();
            var options = room.Options
                .OrderBy(o => o.DisplayOrder)
                .Select(o => new
                {
                    text = o.Text,
                    selected = o.Text == myAnswer.ChosedOptionText,
                    count = room.Answers.Count(a => a.ChosedOptionText == o.Text)
                })
                .ToArray();
            
            return options;
        }
Ejemplo n.º 5
0
 public DefaultController()
 {
     this.Db = new AppDbContext();
 }
Ejemplo n.º 6
0
 private static void ClearMyAnswers(AppDbContext db, Room room, string userID)
 {
     room.Answers
         .Where(a => a.AnsweredUserID == userID)
         .ToList()
         .ForEach(a =>
         {
             room.Answers.Remove(a);
             db.Answers.Remove(a);
         });
 }
Ejemplo n.º 7
0
 private static Room FindRoom(int roomNumber, AppDbContext db)
 {
     var room = db.Rooms
         .Include("Answers")
         .Include("Options")
         .First(r => r.RoomNumber == roomNumber);
     return room;
 }