public HappyHourSummary GetSummary(HappyHoursLoginParameters parameters)
        {
            var data = HackData(parameters);

            var parsedData = ParseData(data);

            parsedData.Hours = FilterDays(parsedData.Hours, parameters.StartDate, parameters.EndDate);

            var result = CalculateData(parsedData);

            return(result);
        }
        private string HackData(HappyHoursLoginParameters loginParameters)
        {
            var url = "https://rt-pay.com/WebRP/";
            var web = new HtmlWeb();
            var doc = web.Load(url);

            var nodes = doc.DocumentNode.
                        Descendants("input").
                        Where(x => x.Attributes["type"].Value == "hidden").ToList();

            var viewState          = nodes.FirstOrDefault(c => c.Id == "__VIEWSTATE").Attributes["value"].Value;
            var viewStateGenerator = nodes.FirstOrDefault(c => c.Id == "__VIEWSTATEGENERATOR").Attributes["value"].Value;
            var eventValidation    = nodes.FirstOrDefault(c => c.Id == "__EVENTVALIDATION").Attributes["value"].Value;

            var values = new Dictionary <string, string>
            {
                { "__VIEWSTATE", viewState },
                { "__VIEWSTATEGENERATOR", viewStateGenerator },
                { "__EVENTVALIDATION", eventValidation },
                { "txtUsername", loginParameters.Credentials.Username },
                { "txtPassword", loginParameters.Credentials.Password },
                { "txtEmployeeNo", loginParameters.Credentials.Number },
                { "btnLogin", "" },
                { "Remember", "rbRememberEmailEmployee" }
            };

            CookieContainer   cookies = new CookieContainer();
            HttpClientHandler handler = new HttpClientHandler();

            handler.CookieContainer = cookies;
            HttpClient           client             = new HttpClient(handler);
            var                  content            = new FormUrlEncodedContent(values);
            var                  response           = client.PostAsync("https://rt-pay.com/WebRP/Default.aspx", content);
            var                  responseString     = response.Result.Content.ReadAsStringAsync().Result;
            Uri                  uri                = new Uri("https://rt-pay.com/WebRP/Default.aspx");
            IEnumerable <Cookie> responseCookies    = cookies.GetCookies(uri).Cast <Cookie>();
            var                  webKitFormBoundary = GenerateWebKitFormBoundary();



            HtmlDocument htmlDocument = new HtmlDocument();

            htmlDocument.LoadHtml(responseString);

            var failedElement = htmlDocument.DocumentNode.Descendants("span").Where(c => c.Id == "lblLogin_Failed").FirstOrDefault();

            if (failedElement != null)
            {
                throw new HappyHourException(ErrorCode.InvalidCredentials);
            }

            var specialValue = htmlDocument.DocumentNode.
                               Descendants("input").
                               Where(x => x.Attributes["type"].Value == "hidden" && x.Attributes["name"].Value == "ctl00$txtSK").FirstOrDefault().Attributes["value"].Value;

            HttpWebRequest oRequest = null;

            oRequest             = (HttpWebRequest)HttpWebRequest.Create("https://rt-pay.com/WebRP/Private/Employee.aspx");
            oRequest.ContentType = "multipart/form-data; boundary=" + webKitFormBoundary.Substring(2, webKitFormBoundary.Length - 2);
            oRequest.Method      = "POST";

            oRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            oRequest.Accept    = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
            oRequest.KeepAlive = true;
            oRequest.Host      = "rt-pay.com";
            oRequest.Referer   = "https://rt-pay.com/WebRP/Private/Employee.aspx";
            oRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36";

            oRequest.Headers.Add("Accept-Encoding", "gzip, deflate, br");
            oRequest.Headers.Add("Accept-Language", "en-US,en;q=0.8");
            oRequest.Headers.Add("Cache-Control", "max-age=0");
            oRequest.Headers.Add("Origin", "https://rt-pay.com");
            oRequest.Headers.Add("Upgrade-Insecure-Requests", "1");

            if (oRequest.CookieContainer == null)
            {
                oRequest.CookieContainer = new CookieContainer();
            }

            foreach (var cookie in responseCookies)
            {
                oRequest.CookieContainer.Add(cookie);
            }

            var parameters = CreateRequestStringFromChromeRequest();

            PostData pData = new PostData(webKitFormBoundary);

            foreach (var parameter in parameters)
            {
                pData.Params.Add(new PostDataParam(parameter.Parameter, parameter.Value, parameter.Type));
            }


            pData.Params.Where(c => c.Name == "__VIEWSTATEGENERATOR").FirstOrDefault().Value = viewStateGenerator;
            pData.Params.Where(c => c.Name == "ctl00$txtSK").FirstOrDefault().Value          = specialValue;

            pData.Params.Where(c => c.Name == "drpYears").FirstOrDefault().Value        = loginParameters.StartDate.Year.ToString();
            pData.Params.Where(c => c.Name == "_drpYears_state").FirstOrDefault().Value = "[{\"value\":" + loginParameters.StartDate.Year + ",\"text\":\"" + loginParameters.StartDate.Year + "\",\"index\":0}]";

            pData.Params.Where(c => c.Name == "drpMonths").FirstOrDefault().Value        = loginParameters.StartDate.Month.ToString();
            pData.Params.Where(c => c.Name == "_drpMonths_state").FirstOrDefault().Value = "[{\"value\":" + loginParameters.StartDate.Month + ",\"text\":\"\u05d9\u05d5\u05dc\u05d9\",\"index\":6}]";

            var data = pData.GetPostData();

            var encoding = Encoding.UTF8;

            byte[] buffer = encoding.GetBytes(data);
            // Set content length of our data
            oRequest.ContentLength = buffer.Length;
            // Dump our buffered postdata to the stream, booyah
            var stream = oRequest.GetRequestStream();

            stream.Write(buffer, 0, buffer.Length);
            stream.Close();

            // get the response
            var    oResponse    = (HttpWebResponse)oRequest.GetResponse();
            string responseText = null;

            using (var reader = new System.IO.StreamReader(oResponse.GetResponseStream(), encoding))
            {
                responseText = reader.ReadToEnd();
            }

            return(responseText);
        }