예제 #1
0
        // GET: api/squadHealth/
        public void Get([FromUri] vote input)
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["directLocalDB"];
            string sprintId = ConfigurationManager.AppSettings["sprintID"];

            SqlConnection conn = new SqlConnection(settings.ToString());

            string mergeCmd = "update tbl_squadHealth set colour = '" + input.colour + "' where userid  ='" + input.userId + "' and questionNumber = '" + input.questionNumber + "' and sprintId = '" + input.sprintId + "'";

            SqlCommand cmd = new SqlCommand(mergeCmd, conn);

            conn.Open();
            var noOfResults = cmd.ExecuteNonQuery();

            if (noOfResults == 0)
            {
                squadHealthEntities db = new squadHealthEntities();

                tbl_squadHealth newObj = new tbl_squadHealth();

                newObj.colour         = input.colour;
                newObj.lastUpdateTime = Convert.ToDateTime(input.lastUpdateTime);
                newObj.questionNumber = Convert.ToInt16(input.questionNumber);
                newObj.sprintId       = Convert.ToInt16(sprintId);
                newObj.userId         = input.userId;

                db.tbl_squadHealth.Add(newObj);
                db.SaveChanges();
            }
        }
예제 #2
0
        // GET: api/teamResult
        public string Get([FromUri] teamResult input)
        {
            squadHealthEntities db = new squadHealthEntities();

            int qNumber = Convert.ToInt16(input.questionNumber);

            var result = (from r in db.tbl_squadHealth
                          where r.questionNumber == qNumber
                          group r by r.colour into g
                          let gCount = g.Count()
                                       orderby gCount
                                       select new { colour = g.Key, colourCount = g.Count() }).FirstOrDefault();

            if (result != null)
            {
                return(result.colour);
            }
            else
            {
                return("green");
            }
        }