Ejemplo n.º 1
0
        //3 hard, 1 easy, -1 gresit
        public IActionResult GetCheckAnswerByQuestionIDAnswerIdUser(string questionID, string answer,string id_user)
        {
            string response="";
            int score = 0;
            try
            {
                database db = new database(database.maindb);
                db.AddParam("?id", questionID);
                MySqlDataReader rd = db.ExecuteReader("select answer from questions where random_id=?id");
                while(rd.Read())
                {
                    if (rd.GetString("answer") == answer) { response = "1";
                        score = 3;
                    }
                    else { response = "0";
                        score = -1;
                    }
                }
                db.AddParam("?score", score);
                db.AddParam("?id_user", id_user);
                db.ExecuteReader("update questions set answered=1 where random_id=?id");
                db.ExecuteReader("update users set score=score+?score where id=?id_user");
            }
            catch
            {

            }
            return new ObjectResult(response);
        }
Ejemplo n.º 2
0
        public IActionResult country(string countryName)
        {
            ViewBag.country = countryName;
            try
            {
                ViewBag.countryExists = "true";
                database db = new database(database.maindb);
                db.AddParam("?country", countryName);
                MySqlDataReader rd = db.ExecuteReader("select * from countries where lower(country)=lower(?country)");
                if (!rd.HasRows)
                {
                    ViewBag.climate = "N.A.";
                    ViewBag.death_rate = "N.A.";
                    ViewBag.obesity = "N.A.";
                }

                while (rd.Read())
                {
                    ViewBag.climate = rd.GetString("climate");
                    double death_rate = rd.GetDouble("death_rate");
                    if (death_rate == 0) ViewBag.death_rate = "N.A.";
                    else ViewBag.death_rate = death_rate;
                    double obesity = rd.GetDouble("obesity");
                    if (obesity == 0) ViewBag.obesity = "N.A.";
                    else ViewBag.obesity = obesity;
                }
                Dictionary<string, Country> cslist = new Countries().getDictionar();
                ViewBag.code = "";
                try
                {
                    ViewBag.code = cslist[countryName].Code;
                }
                catch { }

            }
            catch { }
            ViewBag.nr = 0;
            try
            {
                ObjectResult obj = (ObjectResult)new MeAd.Raml.SearchController().Get(countryName);
                Dictionary<string, Countries.CountryDiseases> countryDiseases = (Dictionary<string, Countries.CountryDiseases>)obj.Value;
                ViewBag.countryDiseases = countryDiseases;
            }
            catch { }
            return View();
        }
Ejemplo n.º 3
0
        public string Login(string username, string password)
        {
            //-1 username or email doesnt exist
            try
            {
                //if (!IsValidEmail(email)) return "-1";

                database db = new database(database.maindb);
                db.AddParam("?username", username);
                db.AddParam("?password", password);
                MySqlDataReader rd = db.ExecuteReader("select * from users where lower(username)=lower(?username) and password=?password");
                if (!rd.HasRows)
                {
                    Context.Session.SetInt32("on", 0);
                    // invalid user / pass
                    db.Close();
                    return "-1";
                }
                while (rd.Read())
                {
                    Context.Session.SetInt32("on", 1);
                    Context.Session.SetInt32("id", rd.GetInt32("id"));
                    Context.Session.SetString("email", rd.GetString("email"));
                    Context.Session.SetString("username", rd.GetString("username"));
                    Context.Session.SetInt32("score", rd.GetInt32("score"));
                    Context.Session.SetString("country", rd.GetString("country"));
                    Context.Session.SetInt32("gender", rd.GetInt32("gender"));
                    Context.Session.SetString("birthday", rd.GetString("birthday"));
                    break;
                }
                db.Close();
            }
            catch (Exception e)
            {
                //  HttpContext.Current.Session["on"] = 0;
                return e.ToString();
            }
            return "1";
        }
Ejemplo n.º 4
0
        public string RegisterUser(string email, string password, string username, string birthday, string gender, string country)
        {
            //-1 username or email already exists, -2 invalid birthday
            try

            {
                database db = new database(database.maindb);
                if (String.IsNullOrEmpty(birthday)) birthday = "";
                if (String.IsNullOrEmpty(country)) country = "";

                db.AddParam("?username", username);
                db.AddParam("?email", email);

                MySqlDataReader rd = db.ExecuteReader("select * from users where lower(email)=lower(?email) or lower(username)=lower(?username)");
                if (rd.HasRows) return "-1";

                DateTime dateValue;
                if (!DateTime.TryParse(birthday, out dateValue) && birthday != "") return "-2";

                int sex = 0;
                switch (gender)
                {
                    case "Gender":
                        sex = 0;
                        break;
                    case "Male":
                        sex = 1;
                        break;
                    case "Female":
                        sex = 2;
                        break;
                }
                db.AddParam("?password", password);
                db.AddParam("?birthday", birthday);
                db.AddParam("?country", country);
                db.AddParam("?gender", sex);

                db.ExecuteNonQuery("insert into users(email,username,password,gender,country,birthday) values (?email,?username,?password,?gender,?country,?birthday)");
                return "1";
            }
            catch (Exception e)
            { return e.ToString(); }
        }
Ejemplo n.º 5
0
        public string FBLogin(string token)
        {
            try
            {
                WebClient wc = new WebClient();
                wc.Proxy = null;

                string res = wc.DownloadString("https://graph.facebook.com/me?fields=email,name,first_name,last_name,gender&access_token=" + token);
                Dictionary<string, string> response = JsonConvert.DeserializeObject<Dictionary<string, string>>(res);
                if (response.ContainsKey("name"))
                {
                    string id = response["id"];
                    string email = response["email"];
                    database db = new database(database.maindb);
                    db.AddParam("?fbid", id);
                    db.AddParam("?email", email);
                    db.AddParam("?username", response["first_name"]+response["last_name"]);

                    switch (response["gender"])
                    {
                        case "male":
                            db.AddParam("?gender", 1);
                            break;
                        case "female":
                            db.AddParam("?gender", 2);
                            break;
                        default:
                            db.AddParam("?gender", 0);
                            break;
                    }

                    MySqlDataReader rd;

                    rd = db.ExecuteReader("select * from users where facebookid = ?fbid or email = ?email");

                    if (rd.HasRows)
                        while (rd.Read())
                        {
                            Context.Session.SetInt32("on", 1);
                            Context.Session.SetString("email", rd.GetString("email"));
                            Context.Session.SetString("username", rd.GetString("username"));
                            Context.Session.SetInt32("id", rd.GetInt32("id"));
                            Context.Session.SetString("myname", rd.GetString("lastname") + " " + rd.GetString("firstname"));
                            break;
                            // return "2";
                        }
                    else
                    {
                        db.ExecuteNonQuery("insert into users (email,username,gender,facebookid) values (?email,?username,?gender,?fbid)");
                        rd = db.ExecuteReader("select * from users where facebookid = ?fbid or email = ?email");
                        while (rd.Read())
                        {
                            Context.Session.SetInt32("on", 1);
                            Context.Session.SetString("email", rd.GetString("email"));
                            Context.Session.SetInt32("id", rd.GetInt32("id"));
                            Context.Session.SetString("username", rd.GetString("username"));
                            Context.Session.SetInt32("gender", rd.GetInt32("gender"));
                        }
                        //return "3";
                    }

                    db.Close();

                    return "1";
                }
                else
                    return "0";
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }