Exemplo n.º 1
0
        public JsonResult AddScore(ScoresModel newScore)
        {
           

            SqlTool sqltool = new SqlTool();
            HandicapCalculator handicap = new HandicapCalculator();

            //populate Course Model

            decimal adjustedScore = handicap.AdjustScore(newScore.score, newScore.courseid);
            
            string newScoreInsert = String.Format(@"INSERT INTO Scores(userid,courseid,score,dateplayed,adjustedscore) SELECT {0},{1},{2},'{3}',{4}",
                                                                    Session["id"], newScore.courseid, newScore.score, newScore.dateplayed.ToShortDateString(), adjustedScore);
            
            sqltool.runQuery(newScoreInsert);
            return Json(newScore, JsonRequestBehavior.AllowGet);
            
        }
Exemplo n.º 2
0
        public JsonResult DeleteScore(ScoresModel scoreToDelete)
        {

            
            SqlTool sqltool = new SqlTool();

            int scoreid = scoreToDelete.id;


            string deleteScoreQuery = @"Delete from Scores where id = " + scoreid;
            sqltool.runQuery(deleteScoreQuery);

            return Json(null, JsonRequestBehavior.AllowGet);

            


        }
Exemplo n.º 3
0
        public JsonResult UpdateScore(ScoresModel scoreToUpdate)
        {
            SqlTool sql = new SqlTool();
            HandicapCalculator handicap = new HandicapCalculator();
            decimal adjustedScore = handicap.AdjustScore(scoreToUpdate.score, scoreToUpdate.courseid);

            string updateScoreQuery = @"Update scores set Score = " + scoreToUpdate.score + ",adjustedscore = " + adjustedScore + " where id = " + scoreToUpdate.id;
            sql.runQuery(updateScoreQuery);


            return Json(null, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 4
0
        public JsonResult Register(UsersModel newUser)
        {

            DataTable dt = new DataTableGenerator().GetDataTable(@"Select * from Users where email = '" + newUser.email.ToString() + "'");

            if (dt.Rows.Count == 1)
            {
                return Json(new UsersModel(), JsonRequestBehavior.AllowGet);
            }
            else
            {
                UsersModel model = new UsersModel();
                SqlTool sql = new SqlTool();

                model.fname = newUser.fname;
                model.lname = newUser.lname;
                model.username = newUser.username;
                model.password = newUser.password;
                model.email = newUser.email;

                sql.runQuery("Insert into Users (fname,lname,email,password,username) select '" + model.fname.ToString() + "','" +
                    model.lname.ToString() + "','" + model.email.ToString() + "','" + model.password.ToString() + "','" +
                    model.username + "'");

                return Json(model, JsonRequestBehavior.AllowGet);

            }



        }