Exemplo n.º 1
0
        public static string EditProfile(string jSonUserRecToEditProfile) //OK

        {
            string retValue = string.Empty;

            foreach (DataRow dr in jsonStringToTable(jSonUserRecToEditProfile).Rows)
            {
                UserDataObj user = new UserDataObj();

                user.UserID = long.Parse(dr["userID"].ToString());

                user.Username = dr["username"].ToString();

                user.Password = dr["password"].ToString();

                UserReps userRps = new UserReps();

                userRps.Update(user);


                retValue = GetAsJson_Simple("userID", user.UserID.ToString());
            }


            return(retValue);
        }
Exemplo n.º 2
0
        public static string SignUp(string UserDataToAdd) //OK

        {
            string retValue = string.Empty;

            foreach (DataRow dr in jsonStringToTable(UserDataToAdd).Rows)
            {
                // New User will be added to database

                UserDataObj user = new UserDataObj();

                user.Username = dr["username"].ToString();

                user.Password = dr["password"].ToString();

                user.Point = 100; //Default

                UserReps userRps = new UserReps();

                userRps.Insert(user);

                retValue = CnvDataTableToJsonString(userRps.Athenticate(user));
            }

            return(retValue);
        }
Exemplo n.º 3
0
        //// Update Point
        //public void UpdatePoint(string userID, int pointToAdd)
        //{


        //    string strCmd = string.Format("Update  public.\"{0}\"  set  \"point\" = \"point\" + {1}  where \"userID\" = {2}", TblName,  pointToAdd.ToString(), userID);

        //    using (NpgsqlCommand cmd = new NpgsqlCommand(strCmd, GetConnection()))
        //    {

        //        cmd.ExecuteNonQuery();

        //    }

        //}

        // Set Admin and add Point
        public void SetAdminUpdatePoint(UserDataObj user, int pointToAdd)
        {
            string strCmd = string.Format("Update  public.\"{0}\"  set  \"isAdmin\" = 1, \"point\" = \"point\" + {1}   where \"userID\" = {2}", TblName, pointToAdd.ToString(), user.UserID.ToString());

            using (NpgsqlCommand cmd = new NpgsqlCommand(strCmd, GetConnection()))
            {
                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 4
0
        public static string IsUserAdmin(string userID) //OK

        {
            UserDataObj user = new UserDataObj();

            user.UserID = long.Parse(userID);

            return(new UserReps().IsUserAdmin(user));
        }
Exemplo n.º 5
0
        public static string GetUserRec(string json_userID) //OK

        {
            long userID = long.Parse(GetSingleValueFromJson(json_userID, "userID"));

            UserDataObj user = new UserDataObj();

            user.UserID = userID;

            DataTable dtPlayers = new UserReps().GetUserRec(user);

            return(CnvDataTableToJsonString(dtPlayers));
        }
Exemplo n.º 6
0
        public PartialViewResult UserDetail()
        {
            var user = new UserDataSettings().GetUserData();

            if (user == null)
            {
                user = new UserDataObj();
            }
            //parentRepeater.DataSource = rst;
            //parentRepeater.DataBind();

            return(PartialView(user));
        }
Exemplo n.º 7
0
        public string IsUserAdmin(UserDataObj user) //OK
        {
            string retVaue = "false";


            string strCmd = string.Format("select \"isAdmin\"  from  public.\"{0}\" where \"userID\" = {1} ", TblName, user.UserID.ToString());

            using (NpgsqlCommand cmd = new NpgsqlCommand(strCmd, GetConnection()))
            {
                retVaue = cmd.ExecuteScalar().ToString().Trim();
            }

            return(retVaue);
        }
Exemplo n.º 8
0
        public UserDataObj Insert(UserDataObj user) //OK
        {
            string strCmd = string.Format("Insert into public.\"{0}\" (username, password, set, point, \"isAdmin\") values ( '{1}', '{2}', '{3}', {4}, '0') ", TblName, user.Username.Trim(), user.Password.Trim(), user.Set, user.Point);

            using (NpgsqlCommand cmd = new NpgsqlCommand(strCmd, GetConnection()))
            {
                cmd.ExecuteNonQuery();

                cmd.CommandText = string.Format("select max(\"userID\") from  public.\"{0}\" ", TblName);

                user.UserID = (long)cmd.ExecuteScalar();
            }

            return(user);
        }
Exemplo n.º 9
0
        public DataTable Athenticate(UserDataObj user)
        {
            var dataTable = new DataTable();

            string strCmd = string.Format("select * from  public.\"{0}\" where ltrim(rtrim(username)) = '{1}' and  ltrim(rtrim(password)) = '{2}' ", TblName, user.Username.Trim(), user.Password.Trim());

            using (NpgsqlCommand cmd = new NpgsqlCommand(strCmd, GetConnection()))
            {
                using (NpgsqlDataReader reader = cmd.ExecuteReader())
                {
                    dataTable.Load(reader);
                }
            }

            return(dataTable);
        }
Exemplo n.º 10
0
        public DataTable GetUserRec(UserDataObj user) //OK
        {
            var dataTable = new DataTable();

            string strCmd = string.Format("select * from  public.\"{0}\" where \"userID\" = {1} ", TblName, user.UserID.ToString());

            using (NpgsqlCommand cmd = new NpgsqlCommand(strCmd, GetConnection()))
            {
                using (NpgsqlDataReader reader = cmd.ExecuteReader())
                {
                    dataTable.Load(reader);
                }
            }

            return(dataTable);
        }
Exemplo n.º 11
0
        public void Update(UserDataObj user) //OK
        {
            //string strCmd = "Update  public.\"Users\"  set username = @username, name=@name, password=@password where  \"userID\" = @userID";

            string strCmd = string.Format("Update  public.\"{0}\"   set username = '******', password = '******'  where \"userID\" = {2}", TblName, user.Username.Trim(), user.Password.Trim(), user.UserID.ToString());

            using (NpgsqlCommand cmd = new NpgsqlCommand(strCmd, GetConnection()))
            {
                //cmd.Parameters.AddWithValue("@userID", this.UserID);

                //cmd.Parameters.AddWithValue("@username", this.Username );

                //cmd.Parameters.AddWithValue("@password", this.Password );


                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 12
0
        // Define Set / Update Set
        public string UpdateSet(UserDataObj user) //OK
        {
            string retValue = " Your Set added succesfully";

            try
            {
                string strCmd = string.Format("Update  public.\"{0}\"   set set = '{1}'  where \"userID\" = {2}", TblName, user.Set.Trim(), user.UserID.ToString());

                using (NpgsqlCommand cmd = new NpgsqlCommand(strCmd, GetConnection()))
                {
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                retValue = ex.Message;
            }

            return(retValue);
        }
Exemplo n.º 13
0
        // Define Set
        public static string DefineSet(string jSonUserRecToDefineSet) //OK

        {
            string retValue = string.Empty;

            UserDataObj user = new UserDataObj();



            foreach (DataRow dr in jsonStringToTable(jSonUserRecToDefineSet).Rows)
            {
                user.UserID = long.Parse(dr["userID"].ToString());

                user.Set = dr["set"].ToString();

                retValue = new UserReps().UpdateSet(user);
            }


            return(retValue);
        }
Exemplo n.º 14
0
        public string SignIn(string UserDataToSignIn) //OK

        {
            string retValue = string.Empty;


            foreach (DataRow dr in jsonStringToTable(UserDataToSignIn).Rows)
            {
                UserDataObj user = new UserDataObj();

                user.Username = dr["username"].ToString();

                user.Password = dr["password"].ToString();

                UserReps userRps = new UserReps();

                userRps.Athenticate(user);

                retValue = JSonUtil_Server.CnvDataTableToJsonString(userRps.Athenticate(user));
            }


            return(retValue);
        }
Exemplo n.º 15
0
        public static string StartToPlay()
        {
            if (BattleSupport.log != string.Empty)
            {
                return(BattleSupport.log);
            }

            new UserReps().ResetAllAdmin();

            string log = " \r\n";

            string padLeft = "";

            TPlayerDataObj tPlayer = new TPlayerDataObj();

            tPlayer.UserID = 0;

            DataTable dtPlayers = new TPlayersReps().GetPlayers(tPlayer);

            dtPlayers.Columns.Add("score", typeof(int));

            foreach (DataRow dr in dtPlayers.Rows)
            {
                dr["score"] = 0;
            }

            int cnt = dtPlayers.Rows.Count;

            for (int i = 1; i < cnt; i++)
            {
                for (int j = 1; i + j < cnt + 1; j++)
                {
                    int result = Fight(dtPlayers.Rows[i - 1]["set"].ToString(), dtPlayers.Rows[i - 1 + j]["set"].ToString());

                    if (result == 1)
                    {
                        dtPlayers.Rows[i - 1]["score"] = int.Parse(dtPlayers.Rows[i - 1]["score"].ToString()) + 1;

                        log += dtPlayers.Rows[i - 1]["username"].ToString() + " defeated " + dtPlayers.Rows[i - 1 + j]["username"].ToString() + " \r\n";
                    }
                    else if (result == 2)
                    {
                        dtPlayers.Rows[i - 1 + j]["score"] = int.Parse(dtPlayers.Rows[i - 1 + j]["score"].ToString()) + 1;

                        log += padLeft + padLeft + dtPlayers.Rows[i - 1 + j]["username"].ToString() + " defeated " + dtPlayers.Rows[i - 1]["username"].ToString() + " \r\n";
                    }
                    else // 0
                    {
                        log += padLeft + "draw between " + dtPlayers.Rows[i - 1 + j]["username"].ToString() + " and " + dtPlayers.Rows[i - 1]["username"].ToString() + " \r\n";
                    }
                }
            }



            int indexOfMaxScore = 0;


            int maxScore = int.Parse(dtPlayers.Rows[0]["score"].ToString());

            for (int i = 1; i < dtPlayers.Rows.Count; i++)

            {
                int nextScore = int.Parse(dtPlayers.Rows[i]["score"].ToString());

                if (nextScore > maxScore)
                {
                    maxScore = nextScore;

                    indexOfMaxScore = i;
                }
            }

            string winerUserID = dtPlayers.Rows[indexOfMaxScore]["userID"].ToString();

            UserDataObj user = new UserDataObj();

            user.UserID = long.Parse(winerUserID);

            new UserReps().SetAdminUpdatePoint(user, 5);

            log += Environment.NewLine;

            log += "---------------------------------------------------------------" + Environment.NewLine;

            log += padLeft + dtPlayers.Rows[indexOfMaxScore]["username"].ToString() + " has won the Tournament and is now the Administator" + Environment.NewLine;

            log += "---------------------------------------------------------------" + Environment.NewLine;

            //  Players.EmptyTournament();

            BattleSupport.log = log;

            return(log);
        }