コード例 #1
0
        //method to create a new user
        public static EmployeeResponseClass CreateUser(Employee u)
        {
            EmployeeRequestClass eRC = new EmployeeRequestClass
            {
                Employee = u,
                Photo    = File.ReadAllBytes(u.PathPhoto)
            };
            string json    = JsonConvert.SerializeObject(eRC);
            var    content = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                HttpResponseMessage response = client.PostAsync(myRest + "/users/employees", content).Result;
                if (response.IsSuccessStatusCode)
                {
                    return(JsonConvert.DeserializeObject <EmployeeResponseClass>(response.Content.ReadAsStringAsync().Result));
                }
                else if (response.StatusCode == (HttpStatusCode)804)
                {
                    LoginWindow lw = new LoginWindow();
                    lw.ShowDialog();
                    if (loggedIn)
                    {
                        return(CreateUser(u));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (AggregateException tk)
            {
                serviceErrorShow();
                Application.Current.Shutdown();
            }
            catch
            {
                Console.WriteLine("TIMEOUT???");
            }
            return(null);
        }
コード例 #2
0
        //method for getting all users
        public static List <Employee> GetAllUsers()
        {
            string json = String.Empty;

            try
            {
                HttpResponseMessage response = client.GetAsync(myRest + "/users/employees").Result;

                if (response.IsSuccessStatusCode)
                {
                    List <Employee> lista = JsonConvert.DeserializeObject <List <Employee> >(response.Content.ReadAsStringAsync().Result);
                    return(lista);
                }
                else if (response.StatusCode == (HttpStatusCode)804)
                {
                    LoginWindow lw = new LoginWindow();
                    lw.ShowDialog();
                    if (loggedIn)
                    {
                        return(GetAllUsers());
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (AggregateException tk)
            {
                serviceErrorShow();
                Application.Current.Shutdown();
            }
            catch
            {
                Console.WriteLine("TIMEOUT???");
            }
            return(null);
        }
コード例 #3
0
        //method to create a visitor
        public static VisitorResponseClass CreateVisitor(Visitor v)
        {
            string json = JsonConvert.SerializeObject(v);

            var content = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                HttpResponseMessage response = client.PostAsync(myRest + "/users/visitors", content).Result;
                if (response.IsSuccessStatusCode)
                {
                    return(JsonConvert.DeserializeObject <VisitorResponseClass>(response.Content.ReadAsStringAsync().Result));
                }
                else if (response.StatusCode == (HttpStatusCode)804)
                {
                    LoginWindow lw = new LoginWindow();
                    lw.ShowDialog();
                    if (loggedIn)
                    {
                        return(CreateVisitor(v));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (AggregateException tk)
            {
                serviceErrorShow();
                Application.Current.Shutdown();
            }
            catch
            {
                Console.WriteLine("TIMEOUT???");
            }
            return(null);
        }
コード例 #4
0
        public static bool ModifyUser(Employee e)
        {
            string json    = JsonConvert.SerializeObject(e);
            var    content = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                HttpResponseMessage response = client.PostAsync(myRest + "/users/modify", content).Result;
                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                else if (response.StatusCode == (HttpStatusCode)804)
                {
                    LoginWindow lw = new LoginWindow();
                    lw.ShowDialog();
                    if (loggedIn)
                    {
                        return(ModifyUser(e));
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (AggregateException tk)
            {
                serviceErrorShow();
                Application.Current.Shutdown();
            }
            catch
            {
                Console.WriteLine("TIMEOUT???");
            }
            return(false);
        }
コード例 #5
0
        //method to ask for a change in QRcode
        public static string QRCodeChange(string id)
        {
            string json    = JsonConvert.SerializeObject(id);
            var    content = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                HttpResponseMessage response = client.PostAsync(myRest + "/users/new_code", content).Result;
                if (response.IsSuccessStatusCode)
                {
                    return(response.Content.ReadAsStringAsync().Result);
                }
                else if (response.StatusCode == (HttpStatusCode)804)
                {
                    LoginWindow lw = new LoginWindow();
                    lw.ShowDialog();
                    if (loggedIn)
                    {
                        return(QRCodeChange(id));
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
            }
            catch (AggregateException tk)
            {
                serviceErrorShow();
                Application.Current.Shutdown();
            }
            catch
            {
                Console.WriteLine("TIMEOUT???");
            }
            return(String.Empty);
        }
コード例 #6
0
        private void button2_Click(object sender, EventArgs e)
        {
            LoginWindow f = new LoginWindow();

            f.ShowDialog();
        }