public bool LoginUser(string userCode, string password) { UserCode = userCode; Password = password; using (RetailDbContext retailDbContext = new RetailDbContext()) { User user = retailDbContext.Users.Where(x => x.UserCode == userCode).FirstOrDefault(); if (user == null) { ulResult = ULResult.NoUserCode; return(false); } else { UserID = user.UserID; if (user.Password != password) { ulResult = ULResult.IncorrectPassword; return(false); } else { Employee emp = retailDbContext.Employees.Where(x => x.UserID == UserID).FirstOrDefault(); if (emp == null) { ulResult = ULResult.EmpNotFound; return(false); } else { EmployeeID = emp.EmployeeID; return(true); } } } } }
static string MakeWebCall(string url, bool isPost = false, UL userLocationToRegister = null, EJ eventJoin = null, int index = 0) { try { using (var client = new WebClient()) { // New code: //client.BaseAddress = new Uri("http://main-1156949061.us-west-2.elb.amazonaws.com/"); client.BaseAddress = "http://www.litewaveinc.com/"; //client.BaseAddress = "http://127.0.0.1:3000/"; //client.Headers.Add("Accept: application/json"); client.Headers.Add("Content-Type", "application/json"); string response = null; if (isPost) { MemoryStream ms = new MemoryStream(); DataContractJsonSerializer jsonSer; if (userLocationToRegister != null) { //Create a Json Serializer for our type jsonSer = new DataContractJsonSerializer(typeof(UL)); // use the serializer to write the object to a MemoryStream jsonSer.WriteObject(ms, userLocationToRegister); } else if (eventJoin != null) { //Create a Json Serializer for our type jsonSer = new DataContractJsonSerializer(typeof(EJ)); // use the serializer to write the object to a MemoryStream jsonSer.WriteObject(ms, eventJoin); } ms.Position = 0; // use a Stream reader to construct the StringContent (Json) StreamReader sr = new StreamReader(ms); //StringContent theContent = new StringContent(sr.ReadToEnd(), System.Text.Encoding.UTF8, "application/json"); string data = sr.ReadToEnd(); byte[] postArray = Encoding.ASCII.GetBytes(data); byte[] responseArray = client.UploadData(url, "POST", postArray); response = Encoding.ASCII.GetString(responseArray); } else { Stream data = client.OpenRead(url); StreamReader reader = new StreamReader(data); response = reader.ReadToEnd(); } if (response != null) { if (isPost && userLocationToRegister != null) { ULResult ulResult = new ULResult(); DataContractJsonSerializer jsonSer; jsonSer = new DataContractJsonSerializer(typeof(ULResult)); byte[] byteArray = Encoding.ASCII.GetBytes(response); MemoryStream stream = new MemoryStream(byteArray); ulResult = (ULResult)jsonSer.ReadObject(stream); ulStack[ULCount] = ulResult._id; ULCount++; } else if (isPost && eventJoin != null) { EventJoin ej = new EventJoin(); DataContractJsonSerializer jsonSer; jsonSer = new DataContractJsonSerializer(typeof(EventJoin)); byte[] byteArray = Encoding.ASCII.GetBytes(response); MemoryStream stream = new MemoryStream(byteArray); ej = (EventJoin)jsonSer.ReadObject(stream); commandsStack[index] = ej; EJCount++; } return(response); } } } catch (WebException webEx) { HttpWebResponse response = (System.Net.HttpWebResponse)webEx.Response; if (response.StatusCode == HttpStatusCode.NotFound) { System.Diagnostics.Debug.WriteLine("Not found!"); } } return(null); }