Ejemplo n.º 1
0
        public ActionResult LeaveRoom(string Id)
        {
            // ID = Room code.
            var roomCode = Id.ToUpperInvariant();

            var writer = SessionService.GetWriter(HttpContext.Session.GetString(SessionVariables.UserId));

            if (writer == null)
            {
                throw new InvalidOperationException("Unable to join a room, you are unidentified.");
            }

            // Try to find the room.
            var room = ApplicationService.FindRoom(roomCode);

            if (room == null)
            {
                SessionService.AddMessage(HttpContext.Session, "A room with that code could not be found, please check the code and try again.");
                return(null);
            }

            HttpContext.Session.SetString(SessionVariables.RoomCode, string.Empty);

            // room.PresentWriters.RemoveAll(w => w.Identifier == writer.Identifier);
            // room.AbsentWriters.Add(writer);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult Room(string Id = "")
        {
            var roomCode = Id;

            var room = ApplicationService.FindRoom(roomCode);

            if (room == null)
            {
                SessionService.AddMessage(HttpContext.Session, "A room with that code could not be found, please check the code and try again.");
                return(View());
            }

            HttpContext.Session.SetString(SessionVariables.RoomCode, room.Code);

            var writer = SessionService.GetWriter(HttpContext.Session.GetString(SessionVariables.UserId));

            if (writer == null)
            {
                throw new InvalidOperationException("Unable to join a room, you are unidentified.");
            }

            ViewBag.Writer = writer;

            return(View(room));
        }
Ejemplo n.º 3
0
        public ActionResult Join(string Id)
        {
            // ID = Room code.
            var roomCode = Id.ToUpperInvariant();

            var writer = SessionService.GetWriter(HttpContext.Session.GetString(SessionVariables.UserId));

            if (writer == null)
            {
                throw new InvalidOperationException("Unable to join a room, you are unidentified.");
            }

            // Try to find the room.
            var room = ApplicationService.FindRoom(roomCode);

            if (room == null)
            {
                SessionService.AddMessage(HttpContext.Session, "A room with that code could not be found, please check the code and try again.");
                return(View(writer));
            }

            if (writer.Color != null)
            {
                if (room.ColorsInUse.Any(c => c.Name == writer.Color.Name))
                {
                    writer.Color = ColorService.RandomColor(room.ColorsInUse);
                }
            }
            else
            {
                writer.Color = ColorService.RandomColor(room.ColorsInUse);
            }

            room.ColorsInUse.Add(writer.Color);

            /*
             * if (!room.PresentWriters.Exists(w => w.Identifier == writer.Identifier))
             * {
             *  room.PresentWriters.Add(writer);
             * }
             *
             * if (room.AbsentWriters.Exists(w => w.Identifier == writer.Identifier))
             * {
             *  room.AbsentWriters.RemoveAll(w => w.Identifier == writer.Identifier);
             * }
             */

            return(RedirectToAction("Room", new { Id = room.Code }));
        }
Ejemplo n.º 4
0
        public ActionResult FirstLine(string Id)
        {
            // ID = Room Code
            var roomCode = Id;

            var room = ApplicationService.FindRoom(roomCode);

            if (room == null)
            {
                SessionService.AddMessage(HttpContext.Session, "A room with that code could not be found, please check the code and try again.");
                return(View());
            }

            return(View(room));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get the current story for a given room and render it into a partial view.
        /// </summary>
        /// <param name="Id">Room code to get the story for.</param>
        /// <returns>
        /// A partial view displaying the room's story.
        /// </returns>
        public ActionResult StoryText(string Id)
        {
            // ID = Room code.
            var roomCode = Id.ToUpperInvariant();

            // Try to find the room.
            var room = ApplicationService.FindRoom(roomCode);

            if (room == null)
            {
                SessionService.AddMessage(HttpContext.Session, "A room with that code could not be found, please check the code and try again.");
                return(null);
            }

            // Return a partial view containing the room's story so far.
            return(PartialView(room.Story));
        }
Ejemplo n.º 6
0
        public ActionResult FirstLine(string Id, string firstLine)
        {
            var roomCode = Id;

            var room = ApplicationService.FindRoom(roomCode);

            if (room == null)
            {
                SessionService.AddMessage(HttpContext.Session, "A room with that code could not be found, please check the code and try again.");
                return(View());
            }

            room.Story.Intro = new StoryFragment {
                Author = room.Owner, Text = firstLine, Ending = false
            };

            return(RedirectToAction("Room", new { Id = roomCode }));
        }
Ejemplo n.º 7
0
        public ActionResult Index(string Id)
        {
            // ID = User name.
            var userName = Id;

            if (!ValidationService.ValidateWriterName(userName).Validated)
            {
                SessionService.AddMessage(HttpContext.Session, "Your name was invalid.");
                return(View());
            }

            var writer = WriterService.Create(userName);

            ApplicationService.AddWriter(writer);
            HttpContext.Session.SetString(SessionVariables.UserId, writer.Identifier.ToString());

            return(RedirectToAction("Start"));
        }
Ejemplo n.º 8
0
        public ActionResult Create(string Id)
        {
            // ID = Room Name
            var roomName = Id;

            // Get writer who is creating the room.
            var writer = SessionService.GetWriter(HttpContext.Session.GetString(SessionVariables.UserId));

            if (writer == null)
            {
                throw new InvalidOperationException("Unable to create a room, you are unidentified.");
            }

            if (!ValidationService.ValidateRoomName(roomName).Validated)
            {
                SessionService.AddMessage(HttpContext.Session, "Your room name was invalid.");
                return(View(writer));
            }

            var room = RoomService.Create(roomName, writer);

            ApplicationService.AddRoom(room);

            // room.Writers.Add(writer);
            // room.PresentWriters.Add(writer);

            if (writer.Color != null)
            {
                if (room.ColorsInUse.Any(c => c.Name == writer.Color.Name))
                {
                    writer.Color = ColorService.RandomColor(room.ColorsInUse);
                }
            }
            else
            {
                writer.Color = ColorService.RandomColor(room.ColorsInUse);
            }

            room.ColorsInUse.Add(writer.Color);

            return(RedirectToAction("FirstLine", new { Id = room.Code }));
        }