예제 #1
0
        public static string DeleteVersion(RestCommand command, int id)
        {
            ProductVersion item = ProductVersions.GetProductVersion(command.LoginUser, id);

            if (item == null)
            {
                throw new RestException(HttpStatusCode.BadRequest);
            }
            if (Products.GetProduct(command.LoginUser, item.ProductID).OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            string result = item.GetXml("Version", true);

            ProductVersions productVersions = new ProductVersions(command.LoginUser);

            using (SqlCommand dbCommand = new SqlCommand())
            {
                dbCommand.CommandText = "DELETE FROM OrganizationProducts WHERE (ProductVersionID = @ProductVersionID)";
                dbCommand.CommandType = CommandType.Text;
                dbCommand.Parameters.Clear();
                dbCommand.Parameters.AddWithValue("@ProductVersionID", id);
                productVersions.ExecuteNonQuery(dbCommand, "OrganizationProducts");

                dbCommand.CommandText = "UPDATE Tickets SET SolvedVersionID = null WHERE (SolvedVersionID = @ProductVersionID)";
                dbCommand.CommandType = CommandType.Text;
                dbCommand.Parameters.Clear();
                dbCommand.Parameters.AddWithValue("@ProductVersionID", id);
                productVersions.ExecuteNonQuery(dbCommand, "Tickets");

                dbCommand.CommandText = "UPDATE Tickets SET ReportedVersionID = null WHERE (ReportedVersionID = @ProductVersionID)";
                dbCommand.CommandType = CommandType.Text;
                dbCommand.Parameters.Clear();
                dbCommand.Parameters.AddWithValue("@ProductVersionID", id);
                productVersions.ExecuteNonQuery(dbCommand, "Tickets");
            }

            item.Delete();
            item.Collection.Save();
            return(result);
        }