// will return all builds in the database
        public List<Build> GetAllBuilds()
        {
            // setup the reader and DB connections
            SqlDataReader rdr = null;//
            SqlConnection buildsDB = new SqlConnection();

            buildsDB.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BuildsConnectionString"].ToString();

            string commStr = "SELECT * FROM Builds";// get all of them

            SqlCommand buildsConn = new SqlCommand(commStr, buildsDB);

            List<Build> returnBuilds = new List<Build>();

            buildsDB.Open();//open the db
            try
            {
                rdr = buildsConn.ExecuteReader();

                if (rdr.HasRows)// get all the builds
                {

                    while (rdr.Read())
                    {
                        Build b = new Build();
                        b.buildID = rdr["buildID"].ToString();
                        b.title = rdr["title"].ToString();
                        b.tags = rdr["tags"].ToString();
                        b.previewImagePath = "previewImagePath";
                        b.manifestPath = rdr["manifestPath"].ToString();
                         //DateTime.Parse(rdr["dateCreated"].ToString());

                        returnBuilds.Add(b);
                    }
                    rdr.Close();
                    buildsDB.Close();

                }

            }
            catch (Exception e)
            {
                Debug.Write(e.Message);
            }
            finally
            {
                rdr.Close();
                rdr = null;
                buildsDB.Close();
            }

            return returnBuilds;// return the set
        }
        public Dictionary<string, int> PostMedia(Build build)
        {
            if (ModelState.IsValid && build != null)
            {
                string s = "test";
            }
            else
            {
                // return it with zero so the app knows it didn't go through
                Dictionary<string,int> retDic = new Dictionary<string,int>();
                retDic.Add("applicationID",0);
                return retDic;
            }

            // setup the reader and DB connections

            SqlConnection buildsDB = new SqlConnection();

            buildsDB.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BuildsConnectionString"].ToString();

            // set the parameters and the command string
            Boolean isNew = true;// flag to decide if this is new
            string commStr = "INSERT INTO Builds (title, tags, manifestPath, buildID) VALUES (@title,@tags,@manifestPath,@buildID)";
            if(GetBuildById(build.applicationID) != null){
                isNew = false;
                commStr = String.Format("UPDATE Builds SET title=@title,tags=@tags,manifestPath=@manifestPath,buildID=@buildID WHERE applicationID = {0}", Convert.ToString(build.applicationID));
                deleteBuildItems(build.applicationID);
            }
            SqlCommand cmdBuild = new SqlCommand(commStr,buildsDB);

            cmdBuild.Parameters.Add("@title", System.Data.SqlDbType.Char);
            cmdBuild.Parameters["@title"].Value = build.title;
            cmdBuild.Parameters.Add("@tags", System.Data.SqlDbType.Char);
            cmdBuild.Parameters["@tags"].Value = build.tags;
            cmdBuild.Parameters.Add("@manifestPath", System.Data.SqlDbType.Char);
            cmdBuild.Parameters["@manifestPath"].Value = build.manifestPath;
            cmdBuild.Parameters.Add("@buildID", System.Data.SqlDbType.Char);
            cmdBuild.Parameters["@buildID"].Value = build.buildID;

            SqlDataReader rdr = null;// set to null and then assign when reading

            buildsDB.Open();//open the db

            int newID = 0;// used to capture the new appID when inserting a new one
            try
            {
                rdr = cmdBuild.ExecuteReader();
                if (rdr.HasRows)
                {
                    int i = 0;// set column index
                    while (rdr.Read())
                    {
                        Debug.WriteLine(rdr.GetName(i));
                        i++;
                    }
                }

                newID = 1;

            }
            catch (Exception e)
            {
                // return it with zero so the app knows it didn't go through
                Dictionary<string, int> retDic = new Dictionary<string, int>();
                retDic.Add("applicationID", 0);
                return retDic;
            }
            finally
            {
                buildsDB.Close();
            }
            // if there were new ones or updated ones, then return the message properly
            //HttpResponseMessage hr = (rows > 0) ? new HttpResponseMessage(HttpStatusCode.OK) : new HttpResponseMessage(HttpStatusCode.BadRequest);

            // return it with zero so the app knows it didn't go through
            Dictionary<string, int> appIDDic = new Dictionary<string, int>();
            if (isNew)
            {
                appIDDic.Add("applicationID", build.applicationID);
            }
            else
            {
                appIDDic.Add("applicationID", newID);
            }

            return appIDDic;// returns a dictionary with the appID in it
        }
        // will get one build based on the id and return it
        public Build GetBuildById(int id)
        {
            // setup the reader and DB connections
            SqlDataReader rdr = null;//
            SqlConnection buildsDB = new SqlConnection();

            buildsDB.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BuildsConnectionString"].ToString();

            string commStr = String.Format("SELECT * FROM Builds WHERE applicationID = {0}", Convert.ToString(id));// get all of them

            SqlCommand buildsConn = new SqlCommand(commStr, buildsDB);

            Build b = null;// set to null for now

            buildsDB.Open();//open the db
            try
            {
                rdr = buildsConn.ExecuteReader();

                if (rdr.HasRows)// get all the builds
                {
                    while (rdr.Read())
                    {
                        b = new Build();

                        b.buildID = rdr["buildID"].ToString();
                        b.title = rdr["title"].ToString();
                        b.tags = rdr["tags"].ToString();
                        b.previewImagePath = "previewImagePath";
                        b.manifestPath = rdr["manifestPath"].ToString();
                        b.applicationID = id;
                        //DateTime.Parse(rdr["dateCreated"].ToString());
                    }

                }

                if (b == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);// let user know it wasn't found
                }

            }
            catch (Exception e)
            {
                Debug.Write(e.Message);
            }
            finally
            {
                rdr.Close();
                rdr = null;
                buildsDB.Close();
            }
            return b;
        }
Esempio n. 4
0
        private int insertNew(Build b)
        {
            SqlConnection buildsDB = new SqlConnection();

            buildsDB.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BuildsConnectionString"].ToString();
           //INSERT INTO BuildItems (caption, fileName, orderNumber, status, thumbnailPath, timeStamp, title, type, buildID, buildItemIDString) VALUES (@caption,  @fileName, @orderNumber, @status, @thumbnailPath, @timeStamp, @title, @type, @buildID, @buildItemIDString)";
            string commStr = "INSERT INTO Builds (title,tags,manifestPath,buildID,email) VALUES (@title,@tags,@manifestPath,@buildID,@email); SELECT SCOPE_IDENTITY();";
                
            // set the parameters and the command string

            SqlCommand cmdBuild = new SqlCommand(commStr, buildsDB);

            cmdBuild.Parameters.Add("@title", System.Data.SqlDbType.Char);
            cmdBuild.Parameters["@title"].Value = b.title;
            cmdBuild.Parameters.Add("@tags", System.Data.SqlDbType.Char);
            cmdBuild.Parameters["@tags"].Value = b.tags;
            cmdBuild.Parameters.Add("@manifestPath", System.Data.SqlDbType.Char);
            cmdBuild.Parameters["@manifestPath"].Value = b.manifestPath;
            cmdBuild.Parameters.Add("@buildID", System.Data.SqlDbType.Char);
            cmdBuild.Parameters["@buildID"].Value = b.buildID;
            string emailToUse = (b.email == null) ? "anonymous" : b.email;
            cmdBuild.Parameters.Add("@email", System.Data.SqlDbType.Char);
            cmdBuild.Parameters["@email"].Value = emailToUse;
            int newIntTest = -1;
            buildsDB.Open();
            try
            {
                newIntTest = Convert.ToInt32(cmdBuild.ExecuteScalar());
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                buildsDB.Close();
            }

            return newIntTest;
        }
Esempio n. 5
0
        public List<Build> GetAllBuilds()// will return all builds in the database
        {


            // setup the reader and DB connections
            SqlDataReader rdr = null;//
            SqlConnection buildsDB = new SqlConnection();

            buildsDB.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BuildsConnectionString"].ToString();
            string commStr = null;

            commStr = "SELECT * FROM Builds WHERE (active = 'true')";// get all of them
            if (User.Identity.IsAuthenticated)
            {
                Dictionary<string, string> newDic = getUser();
                string role = newDic["role"].Trim();
                if (role == "admin")
                {
                    commStr = "SELECT * FROM Builds";// get all of them
                }
            }


            SqlCommand buildsConn = new SqlCommand(commStr, buildsDB);

            List<Build> returnBuilds = new List<Build>();

            buildsDB.Open();//open the db
            try
            {
                rdr = buildsConn.ExecuteReader();
                if (rdr.HasRows)// get all the builds 
                {

                    while (rdr.Read())
                    {
                        Build b = new Build();
                        b.buildID = rdr["buildID"].ToString();
                        b.title = rdr["title"].ToString();
                        b.tags = rdr["tags"].ToString();
                        b.previewImagePath = "previewImagePath";
                        b.manifestPath = rdr["manifestPath"].ToString();
                        //DateTime.Parse(rdr["dateCreated"].ToString());
                        b.applicationID = (int)rdr["applicationID"];
                        b.email = rdr["email"].ToString();
                        b.active = rdr["active"].ToString();
                        returnBuilds.Add(b);
                    }
                    rdr.Close();
                    buildsDB.Close();

                }

            }
            catch (Exception e)
            {
                Debug.Write(e.Message);
            }
            finally
            {
                rdr.Close();
                rdr = null;
                buildsDB.Close();
            }

            return returnBuilds;// return the set
        }
Esempio n. 6
0
        public Dictionary<string, string> PostMedia(Build build)
        {

            Dictionary<string, string> appIDDic = new Dictionary<string, string>();
            string returnMsg = null;
            if (ModelState.IsValid && build == null)
            {
                // return it with zero so the app knows it didn't go through
               
                appIDDic.Add("error", "Uploaded items are not valid");
                return appIDDic;
            }

            // setup the reader and DB connections

            SqlConnection buildsDB = new SqlConnection();

            buildsDB.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["BuildsConnectionString"].ToString();


            // set the parameters and the command string
            string commStr = String.Format("UPDATE Builds SET title=@title,tags=@tags WHERE applicationID = {0}", Convert.ToString(build.applicationID));
            int newID = 0;// used to capture the new appID when inserting a new one
            if (!CheckExisting(build.applicationID))
            {
               newID = insertNew(build);
               returnMsg = String.Format("INSERTED - {0}",newID);
                
            }else{// delete and set the newID
                deleteBuildItems(build.buildID);
                newID = build.applicationID;
                try
                {
                    // make the updates
                    SqlCommand cmdBuild = new SqlCommand(commStr, buildsDB);

                    cmdBuild.Parameters.Add("@title", System.Data.SqlDbType.Char);
                    cmdBuild.Parameters["@title"].Value = build.title;
                    cmdBuild.Parameters.Add("@tags", System.Data.SqlDbType.Char);
                    cmdBuild.Parameters["@tags"].Value = build.tags;

                    buildsDB.Open();//open the db
                    int i = cmdBuild.ExecuteNonQuery();
                    returnMsg = String.Format("UPDATED - {0}",newID);

                }
                catch (Exception e)
                {
                    // return it with zero so the app knows it didn't go through
                    Dictionary<string, string> retDic = new Dictionary<string, string>();
                    retDic.Add("failureNoAdd", "-2");
                    retDic.Add("errorMsg", e.Message);

                    return retDic;
                }
                finally
                {
                    buildsDB.Close();
                }
            }
            
            
            
            appIDDic.Add("status", returnMsg);

            appIDDic.Add("ID", Convert.ToString(newID));

            return appIDDic;// returns a dictionary with the appID in it
        }