Exemplo n.º 1
0
 // api/Parts
 /// <summary>
 /// Use Connector to connect to DB.
 /// </summary>
 /// <param name="token">The private key.</param>
 /// <returns>A list of parts that was created from the DB on Willie's Server.</returns>
 public IEnumerable<Part> Get (string token)
 {
     if (!token.Equals(key))
     {
         return new List<Part>();
     }
     else
     {
         Connector connector = new Connector();
         return connector.Get("SELECT * Parts");
     }
 }
Exemplo n.º 2
0
        // api/Parts
        /// <summary>
        /// Use Connector to connect to DB. Formulate query to pass to DB.
        /// </summary>
        /// <param name="year">The year of the part.</param>
        /// <param name="make">The make of the part.</param>
        /// <param name="partName">The name of the part.</param>
        /// <param name="token">The private key.</param>
        /// <returns>A list of parts satisfying the query conditions that was 
        /// created from the DB on Willie's Server.</returns>
        /*public IEnumerable<Part> Get(string year, string make, string partName, string token)
        {
            if (!token.Equals(key))
            {
                return new List<Part>();
            }
            else
            {
                Connector connector = new Connector();
                if (make != null && make.Length > 1)
                {
                    make = make.Substring(0, 1);
                }

                var queryPartName = partName;
                if (queryPartName != null && queryPartName.Contains("'"))
                {
                    queryPartName = queryPartName.Replace("'", "''");
                }

                if (queryPartName != null && !queryPartName.Equals(""))
                {
                    var list = connector.Get("SELECT * FROM Parts WHERE YR = \'" + year + "\' AND "
                        + "PartName = \'" + queryPartName + "\' AND " + "Make like \'" + make + "%\'");

                    return list;
                }
                else
                {
                    return new List<Part>();
                }
            }
        }*/
        
        // This addition was put in to facilitate querying for a range of years, it returns a list of parts for a range of years
        /// 4/23/2016 addition 1 begin

        public IEnumerable<Part> Get(string year, string year2, string make, string partName, string token)
        {
            if (!token.Equals(key))
            {
                return new List<Part>();
            }
            else
            {
                Connector connector = new Connector();
                if (make != null && make.Length > 1)
                {
                    make = make.Substring(0, 1);
                }

                var queryPartName = partName;
                if (queryPartName != null && queryPartName.Contains("'"))
                {
                    queryPartName = queryPartName.Replace("'", "''");
                }

                if (queryPartName != null && !queryPartName.Equals(""))
                {
                    var list = connector.Get("SELECT * FROM Parts WHERE (YR BETWEEN\'" + year + "\' AND \'" + year2 + "\') AND (PartName = \'" + queryPartName + "\') AND (Make like \'" + make + "%\')");

                    return list;
                }
                else
                {
                    return new List<Part>();
                }
            }
        }