Ejemplo n.º 1
0
        public HttpResponseMessage Join(int ID, DTO.Character character)
        {
            string errorResponse = "";

            try
            {
                DTO.Session session = SessionConverter.DomainToDTO(RepositoryProxy.Instance.SessionRepository.AddPlayer(ID, character));

                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

                JObject JSession = JObject.FromObject(session);

                response.Content = new System.Net.Http.StringContent(JSession.ToString());

                response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                return(response);
            }
            catch (Exception ex)
            {
                errorResponse = ex.Message;
            }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage GetSessions(string name)
        {
            string errorResponse = "";

            try
            {
                List <DTO.Session> sessions = new List <DTO.Session>();
                foreach (var s in RepositoryProxy.Instance.SessionRepository.GetPlayerSessions(name))
                {
                    sessions.Add(SessionConverter.DomainToDTO(s));
                }

                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

                JArray JSessions = JArray.FromObject(sessions);

                response.Content = new System.Net.Http.StringContent(JSessions.ToString());

                response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                return(response);
            }
            catch (Exception ex)
            {
                errorResponse = ex.Message;
            }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest));
        }
Ejemplo n.º 3
0
        public HttpResponseMessage Create(DTO.Session session)
        {
            string error = "";

            try
            {
                session = SessionConverter.DomainToDTO(RepositoryProxy.Instance.SessionRepository.Add(session));
                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
                JObject             JSession = JObject.FromObject(session);
                response.Content = new System.Net.Http.StringContent(JSession.ToString());
                response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                return(response);
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            HttpResponseMessage errorResponse = new HttpResponseMessage();

            errorResponse.StatusCode   = HttpStatusCode.BadRequest;
            errorResponse.ReasonPhrase = error;
            return(errorResponse);
        }