Ejemplo n.º 1
0
        private IHttpContext GetHandler(IHttpContext context)
        {
            context.Response.ContentType = ContentType.JSON;

            String json;

            try
            {
                var idValues = context.Request.QueryString.GetValues("id");
                if (idValues != null && idValues.Length > 0)
                {
                    var id    = idValues[0];
                    var genre = _dataService.GetGenreByGenreId(id);
                    json = _jsonService.Write(genre);
                }
                else
                {
                    var genres = _dataService.GetGenres();
                    json = _jsonService.Write(genres);
                }
            }
            catch (Exception e)
            {
                context.Response.StatusCode = HttpStatusCode.InternalServerError;
                json = _jsonService.Write(new ErrorMessage(e.Message));
            }

            context.Response.SendResponse(Encoding.ASCII.GetBytes(json));
            return(context);
        }