Ejemplo n.º 1
0
        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;
            }));
        }
Ejemplo n.º 2
0
        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;
            }));
        }