Exemplo n.º 1
0
        private static string GetDeleteQuery(DeleteData data)
        {
            string Query = "";

            if (data.IsLink.Equals("true"))
            {
                Query = "Declare @DID INT; " +
                        "SET @DID = (SELECT Links.DataID FROM Links JOIN Classes ON Links.DataID = Classes.DataID " +
                        "WHERE Links.Name = @Name AND Classes.Class = @Class INTERSECT " +
                        "SELECT UserIDs.DataID FROM UserIDs JOIN Cookies ON UserIDs.UserID = Cookies.UserID " +
                        "WHERE Cookies.Cookie = @Cookie); " +
                        "DELETE FROM Classes WHERE Classes.DataID = @DID; " +
                        "DELETE FROM Units WHERE Units.DataID = @DID; " +
                        "DELETE FROM Types WHERE Types.DataID = @DID; " +
                        "DELETE FROM Comments WHERE Comments.dataID = @DID; " +
                        "DELETE FROM UserIDs WHERE UserIDs.DataID = @DID; " +
                        "DELETE FROM Links WHERE Links.DataID = @DID; ";
            }
            else
            {
                Query = "Declare @DID INT; " +
                        "SET @DID = (SELECT Files.DataID FROM Files JOIN Classes ON Files.DataID = Classes.DataID " +
                        "WHERE Files.Name = @Name AND Classes.Class = @Class INTERSECT " +
                        "SELECT UserIDs.DataID FROM UserIDs JOIN Cookies ON UserIDs.UserID = Cookies.UserID " +
                        "WHERE Cookies.Cookie = @Cookie); " +
                        "DELETE FROM Classes WHERE Classes.DataID = @DID; " +
                        "DELETE FROM Units WHERE Units.DataID = @DID; " +
                        "DELETE FROM Types WHERE Types.DataID = @DID; " +
                        "DELETE FROM Comments WHERE Comments.dataID = @DID; " +
                        "DELETE FROM UserIDs WHERE UserIDs.DataID = @DID; " +
                        "DELETE FROM Files WHERE Files.DataID = @DID; ";
            }
            return(Query);
        }
Exemplo n.º 2
0
        public void Delete(DeleteData data)
        {
            if (IsNullOrEmpty(data.Name) || IsNullOrEmpty(data.Class) || IsNullOrEmpty(data.Cookie) || IsNullOrEmpty(data.IsLink))
            {
                SetStatus(HttpStatusCode.Forbidden);
                return;
            }
            string Query = GetDeleteQuery(data);

            using (SqlCommand com = new SqlCommand(Query, FilerDB2Connection))
            {
                com.Parameters.AddWithValue("@Name", data.Name);
                com.Parameters.AddWithValue("@Class", data.Class);
                com.Parameters.AddWithValue("@Cookie", data.Cookie);
                using (SqlDataReader reader = com.ExecuteReader())
                {
                    reader.Read();
                    if (reader.RecordsAffected > 0)
                    {
                        SetStatus(HttpStatusCode.OK);
                        return;
                    }
                    else
                    {
                        SetStatus(HttpStatusCode.Conflict);
                        return;
                    }
                }
            }
        }