示例#1
0
        public ActionResult Join(string id)
        {
            Guid guidId = Guid.Empty;

            if (!Guid.TryParse(id, out guidId))
            {
                return(StatusCode((int)System.Net.HttpStatusCode.NotFound));
            }

            var selected      = this.GameStore.LoadById(guidId);
            var joiningPlayer = this.PlayerStore.GetPlayer(this.User);

            if (selected == null)
            {
                return(StatusCode((int)System.Net.HttpStatusCode.NotFound));
            }

            if (!selected.CanJoin(joiningPlayer))
            {
                return(StatusCode((int)System.Net.HttpStatusCode.NotAcceptable));
            }

            selected.AddPlayer(joiningPlayer);
            GameStore.Save(selected);

            return(selected.State == GameStatus.ReadyToStart ?
                   StatusCode((int)System.Net.HttpStatusCode.Created) :
                   StatusCode((int)System.Net.HttpStatusCode.OK));
        }