using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using System.Net.Http;
using System.Web.Http;

namespace WebServer
{
    public class UserController : BaseController
    {
        [HttpGet]
        public HttpResponseMessage Index()
        {
            var getParams = Request.GetQueryNameValuePairs();// GetParameters(data);
            var db = new EEEntities();

            var sb = new System.Text.StringBuilder();
            sb.AppendLine("List");
            sb.AppendLine("Gcode");

            //System.Web.Http.Results.JsonResult<string> 
            //var json = JsonConvert.SerializeObject(liast);
            return new HttpResponseMessage()
            {
                Content = new StringContent(
                sb.ToString(),
                System.Text.Encoding.UTF8,
                "text/html")
            };
        }

        [HttpGet]
        public HttpResponseMessage List()
        {
            var getParams = Request.GetQueryNameValuePairs();// GetParameters(data);
            using (var db = new EEEntities())
            {
                var vGcode = "EET1P";
                var liast = db.vGroupUser.AsNoTracking().Where(t => t.gcode == vGcode).OrderBy(t => t.id).ToArray();

                //System.Web.Http.Results.JsonResult<string> 
                var json = JsonConvert.SerializeObject(liast);
                return new HttpResponseMessage()
                {
                    Content = new StringContent(
                    json.ToString(),
                    System.Text.Encoding.UTF8,
                    "application/json")
                };

            }

        }

        
    }
}
