Exemple #1
0
        public string create(parentCreate parent)
        {
            Guid parentId = Guid.NewGuid();

            try{
                SqlConnection con = new SqlConnection(data);
                SqlCommand    cmd = new SqlCommand("INSERT INTO courseParent (parentId, name, creator, courseId) VALUES (@parentId, @name, @creator, @courseId)", con);
                cmd.Parameters.AddWithValue("@parentId", parentId);
                cmd.Parameters.AddWithValue("@name", parent.name);
                cmd.Parameters.AddWithValue("@creator", parent.user);
                cmd.Parameters.AddWithValue("@courseId", parent.courseId);

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (SqlException ex)
            {
                return(ex.ToString());
            }
            catch
            {
                return("Error");
            }

            return(parentId.ToString());
        }
Exemple #2
0
        public string createString(string name, string user, string courseId)
        {
            if (name == null || name.Length <= 0)
            {
                return("Name Null");
            }
            if (user == null || user.Length <= 0)
            {
                return("user Null");
            }
            if (courseId == null || courseId.Length <= 0)
            {
                return("courseId Null");
            }
            string response = "Error";

            try
            {
                parentCreate creator = new parentCreate();
                creator.name     = name;
                creator.user     = new Guid(user);
                creator.courseId = new Guid(courseId);
                response         = create(creator);
            }
            catch
            {
                return(response + 2);
            }
            return(response);
        }