コード例 #1
0
ファイル: UsersController.cs プロジェクト: nnaidenov/Games
        public HttpResponseMessage UserDetails(
            [ValueProvider(typeof(HeaderValueProviderFactory <string>))]
            string sessionKey)
        {
            return(this.ExecuteOperationAndHandleExceptions(() =>
            {
                var context = new GameContext();
                var user = UserPersister.GetUserBySessionKey(sessionKey, context);

                var model = new UserDetails
                {
                    Nickname = user.Nickname,
                    Username = user.Username,
                    Heroes = (
                        from h in user.Heroes
                        select new ViewHeroModel
                    {
                        Id = h.Id,
                        Name = h.Name
                    }),
                    Avatar = user.Avatar
                };

                var response = this.Request.CreateResponse(HttpStatusCode.OK, model);
                return response;
            }));
        }
コード例 #2
0
ファイル: UsersController.cs プロジェクト: nnaidenov/Games
        public HttpResponseMessage LogoutUser(
            [ValueProvider(typeof(HeaderValueProviderFactory <string>))]
            string sessionKey)
        {
            return(this.ExecuteOperationAndHandleExceptions(() =>
            {
                var context = new GameContext();
                var user = UserPersister.GetUserBySessionKey(sessionKey, context);
                user.SessionKey = null;
                context.SaveChanges();

                var response = this.Request.CreateResponse(HttpStatusCode.NoContent);
                return response;
            }));
        }